Selecting Property Views in Microsoft PropertyGrid

Applies to TestComplete 14.30, last modified on November 21, 2019

The PropertyGrid control supports multiple property views - alphabetical, categorized and others. To switch between different views, the users can select the corresponding button on the grid’s embedded toolbar. It is also possible to select the desired view programmatically. This topic explains how you can switch between different PropertyGrid property views from your test scripts.

To perform these actions, TestComplete should have access to internal objects, properties and methods of the PropertyGrid control. For this purpose, the .NET Application Support and Microsoft Control Support plugins must be installed and enabled.

When testing Microsoft PropertyGrid controls, use specific methods and properties of the corresponding MicrosoftPropertyGrid object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing a PropertyGrid control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Simulating Toolbar Button Clicks

In order to switch between different property views, you can simulate clicks on the toolbar buttons. Note that the toolbar in the PropertyGrid control is only visible if the grid’s ToolbarVisible property is True. If this property is False, the toolbar is hidden and it is impossible to click its buttons.

The object that corresponds to the grid toolbar appears as the child object of the grid. You can obtain it in the following way:

  • In applications created in Microsoft Visual Studio .NET, the PropertyGrid control has the standard Win32 toolbar. You can obtain the toolbar using the following statement:
    grid.WinFormsObject("GridToolBar", "")
    It will return the Win32Toolbar object that contains native properties and methods of the toolbar control, as well as extended properties and methods provided by TestComplete.
  • In applications created in Microsoft Visual Studio 2005, the PropertyGrid control uses the ToolStrip toolbar. To obtain the toolbar object, you need to use the following statement:
    grid.WinFormsObject("ToolStrip", "PropertyGridToolBar")
    It will return the StripToolBar object that contains native properties and methods of the toolbar control, as well as extended properties and methods provided by TestComplete.

To simulate a click on a PropertyGrid’s toolbar item, you can use the ClickItem action added to toolbar objects by TestComplete. The item to be clicked can be specified by its caption, identifier or position within the toolbar (see the action description for details):

  • In Visual Studio .NET applications, buttons of the PropertyGrid toolbar do not have captions, so you can specify the desired item by its position within the toolbar. For example, the position of the Categorized button is 0, the Alphabetical button - 1, and so on.
  • If the tested application was created in Visual Studio 2005, you can specify PropertyGrid toolbar buttons by their position as well as by their captions. For example, to click the Alphabetical item, you should pass 0 or “Alphabetical” as a parameter of the ClickItem action.

JavaScript, JScript

// Clicks the specified toolbar item
function ClickTabItem (Grid, Item)
{
  if (Grid.ToolbarVisible)
    // Use the following line for Microsoft Visual Studio .NET applications --
    // Grid.WinFormsObject("GridToolBar", "").ClickItem(Item)
    // Use the following line for Microsoft Visual Studio 2005 applications --
    Grid.WinFormsObject("TooStrip", "PropertyGridToolBar").ClickItem(Item)
  else
    Log.Error ("Cannot click the toolbar item because the toolbar is invisible.");
}

function Main ()
{
  var Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1");

  // Click the "Alphabetical" button
  ClickTabItem (Grid, 1);
  // Click the "Categorized" button
  ClickTabItem (Grid, 0);
}

Python

# Clicks the specified toolbar item
def ClickTabItem (Grid, Item):
  if Grid.ToolbarVisible:
    # Use the following line for Microsoft Visual Studio .NET applications --
    # Grid.WinFormsObject("GridToolBar", "").ClickItem(Item)
    # Use the following line for Microsoft Visual Studio 2005 applications --
    Grid.WinFormsObject("TooStrip", "PropertyGridToolBar").ClickItem(Item)
  else:
    Log.Error ("Cannot click the toolbar item because the toolbar is invisible.");

def Main ():
  Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1");

  # Click the "Alphabetical" button
  ClickTabItem (Grid, 1);
  # Click the "Categorized" button
  ClickTabItem (Grid, 0);

VBScript

' Clicks the specified toolbar item
Sub ClickTabItem (Grid, Item)
  If Grid.ToolbarVisible Then
    ' Use the following line for Microsoft Visual Studio .NET applications --
    ' Grid.WinFormsObject("GridToolBar", "").ClickItem Item
    ' Use the following line for Microsoft Visual Studio 2005 applications --
    Grid.WinFormsObject("TooStrip", "PropertyGridToolBar").ClickItem Item
  Else
    Log.Error "Cannot click the toolbar item because the toolbar is invisible."
  End If
End Sub

Sub Main
  Dim Grid
  Set Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1")

  ' Click the "Alphabetical" button
  Call ClickTabItem (Grid, 1)
  ' Click the "Categorized" button
  Call ClickTabItem (Grid, 0)
End Sub

DelphiScript

// Clicks the specified toolbar item
procedure ClickTabItem (Grid, Item);
begin
  if Grid.ToolbarVisible then
    // Use the following line for Microsoft Visual Studio .NET applications --
    // Grid.WinFormsObject('GridToolBar', '').ClickItem(Item)
    // Use the following line for Microsoft Visual Studio 2005 applications --
    Grid.WinFormsObject('TooStrip', 'PropertyGridToolBar').ClickItem(Item)
  else
    Log.Error ('Cannot click the toolbar item because the toolbar is invisible.');
end;

procedure Main;
var Grid : OleVariant;
begin
  Grid := Sys.Process('PropertyGridSample').WinFormsObject('Form1').WinFormsObject('propertyGrid1');

  // Click the 'Alphabetical' button
  ClickTabItem (Grid, 1);
  // Click the 'Categorized' button
  ClickTabItem (Grid, 0);
end;

C++Script, C#Script

// Clicks the specified toolbar item
function ClickTabItem (Grid, Item)
{
  if (Grid["ToolbarVisible"])
    // Use the following line for Microsoft Visual Studio .NET applications --
    // Grid["WinFormsObject"]("GridToolBar", "")["ClickItem"](Item)
    // Use the following line for Microsoft Visual Studio 2005 applications --
    Grid["WinFormsObject"]("TooStrip", "PropertyGridToolBar")["ClickItem"](Item)
  else
    Log["Error"]("Cannot click the toolbar item because the toolbar is invisible.");
}

function Main ()
{
  var Grid = Sys["Process"]("PropertyGridSample")["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");

  // Click the "Alphabetical" button
  ClickTabItem (Grid, 1);
  // Click the "Categorized" button
  ClickTabItem (Grid, 0);
}

Using the PropertyGrid.PropertySort Property

The PropertyGrid control has the PropertySort property that can be used to determine or specify the sort type in the grid. When setting this property, you can use one of the following string values: “Alphabetical”, “Categorized”, “CategorizedAlphabetical” (the same as “Categorized”) or “NoSort”. The state of the toolbar button changes to reflect the current PropertySort value. For example, if you set PropertySort to “Alphabetical”, the toolbar’s Alphabetical button becomes pressed, and so on. Note, that the PropertySort property can be used regardless of whether the grid's toolbar is visible or not, since it just changes the order that the items are displayed in the grid.

JavaScript, JScript

function Main ()
{
  var Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  var SortModes = new Array ("Alphabetical", "Categorized", "NoSort");

  for (var i=0; i<3; i++)
  {
    Grid.PropertySort = SortModes[i];
    aqUtils.Delay (1000);
  }
}

Python

def Main ():
  Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  SortModes = list("Alphabetical", "Categorized", "NoSort");

  for i in range(0, 2):
    Grid.PropertySort = SortModes[i];
    aqUtils.Delay (1000);

VBScript

Sub Main
  Dim Grid, SortModes, i
  Set Grid = Sys.Process("PropertyGridSample").WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  SortModes = Array ("Alphabetical", "Categorized", "NoSort")

  For i=0 To 2
    Grid.PropertySort = SortModes(i)
    aqUtils.Delay 1000
  Next
End Sub

DelphiScript

procedure Main;
var
  Grid, i : OleVariant;
  Sortmodes : array [0..2];
begin
  Grid := Sys.Process('PropertyGridSample').WinFormsObject('Form1').WinFormsObject('propertyGrid1');
  SortModes[0] := 'Alphabetical';
  SortModes[1] := 'Categorized';
  SortModes[2] := 'NoSort';

  for i:=0 to 2 do
  begin
    Grid.PropertySort := SortModes[i];
    aqUtils.Delay (1000);
  end;
end;

C++Script, C#Script

function Main ()
{
  var Grid = Sys["Process"]("PropertyGridSample")["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");
  var SortModes = new Array ("Alphabetical", "Categorized", "NoSort");

  for (var i=0; i<3; i++)
  {
    Grid["PropertySort"] = SortModes[i];
    aqUtils["Delay"] (1000);
  }
}

See Also

Working With Microsoft PropertyGrid

Highlight search results