The PropertyGrid control uses a variety of editors to configure its item values. For example, the “Appearance.Font” property can be configured via the Font dialog, the “Appearance.FormBorderStyle” property - via the dropdown options list, and so on. This topic explains how you can invoke popup editors and work with dropdown list box editors:
|  | 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  | 
Simulating Actions Over the In-place Editor’s Button
For items that have complex values, PropertyGrid displays a button on the right of the value. Pressing this button invokes the editor for this property (it can be a dropdown control, a dialog, and so on). To click on this button in your scripts, you can use the ClickValueXY action. However, it requires that you know the button coordinates within the item’s cell value. An easier approach is to simulate the keyboard shortcut for this button - F4. You can send this keystroke to the PropertyGrid control using the Keys action.
The following example demonstrates how you can invoke a complex editor for a PropertyGrid item. It modifies the “Appearance.Font” item value via the standard Font dialog:
JavaScript, JScript
function Main ()
{
  var p, Grid, dlg;
  // Obtain the grid object
  p = Sys.Process("PropertyGridSample");
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  // Invoke the "Font" dialog
  Grid.wItems("Appearance").ClickLabel("Font");
  Grid.Keys("[F4]");
  // Simulate actions in the Font dialog
  dlg = p.Window("#32770", "Font");
  dlg.Window("ComboBox", "", 2).ClickItem("Italic");
  dlg.Window("ComboBox", "", 3).ClickItem("10");
  dlg.Window("Button", "OK").ClickButton();
}
Python
def Main ():
  # Obtain the grid object
  p = Sys.Process("PropertyGridSample")
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  # Invoke the "Font" dialog
  Grid.wItems["Appearance"].ClickLabel("Font")
  Grid.Keys("[F4]")
  # Simulate actions in the Font dialog
  dlg = p.Window("#32770", "Font")
  dlg.Window("ComboBox", "", 2).ClickItem("Italic")
  dlg.Window("ComboBox", "", 3).ClickItem("10")
  dlg.Window("Button", "OK").ClickButton()VBScript
Sub Main
  Dim p, Grid, dlg
  ' Obtain the grid object
  Set p = Sys.Process("PropertyGridSample")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  ' Invoke the "Font" dialog
  Grid.wItems("Appearance").ClickLabel("Font")
  Grid.Keys("[F4]")
  ' Simulate actions in the Font dialog
  Set dlg = p.Window("#32770", "Font")
  dlg.Window("ComboBox", "", 2).ClickItem("Italic")
  dlg.Window("ComboBox", "", 3).ClickItem("10")
  dlg.Window("Button", "OK").ClickButton
End Sub
DelphiScript
procedure Main;
var p, Grid, dlg : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('PropertyGridSample');
  Grid := p.WinFormsObject('Form1').WinFormsObject('propertyGrid1');
  // Invoke the "Font" dialog
  Grid.wItems['Appearance'].ClickLabel('Font');
  Grid.Keys('[F4]');
  // Simulate actions in the Font dialog
  dlg := p.Window('#32770', 'Font');
  dlg.Window('ComboBox', '', 2).ClickItem('Italic');
  dlg.Window('ComboBox', '', 3).ClickItem('10');
  dlg.Window('Button', 'OK').ClickButton();
end;
C++Script, C#Script
function Main ()
{
  var p, Grid, dlg;
  // Obtain the grid object
  p = Sys["Process"]("PropertyGridSample");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");
  // Invoke the "Font" dialog
  Grid["wItems"]("Appearance")["ClickLabel"]("Font");
  Grid["Keys"]("[F4]");
  // Simulate actions in the Font dialog
  dlg = p["Window"]("#32770", "Font");
  dlg["Window"]("ComboBox", "", 2)["ClickItem"]("Italic");
  dlg["Window"]("ComboBox", "", 3)["ClickItem"]("10");
  dlg["Window"]("Button", "OK")["ClickButton"]();
}
Working With Dropdown ListBox Editors
Most items displayed in the PropertyGrid control take one of the predefined values (for example, enumeration values). For these items, PropertyGrid selects the needed value from the dropdown options list. As mentioned above, the list is displayed upon the F4 keypress or a click on the down arrow button. After this list box control is displayed on screen, you can access it using the following statement:
gridObj.GetPropertyGridView().DropDownList
This statement returns a “native” .NET object that corresponds to the list box control. You can obtain the TestComplete Win32ListBox object that corresponds to the list box by its handle (the Handle property value) using the Sys.WindowFromHandle method. This lets you work with the list box control using properties, methods and actions of the Win32ListBox object. For instance, to select a specific list box item, you can use the Win32ListBox.ClickItem or SelectItem action.
The following example demonstrates how you can select items in dropdown list box editors:
Example
JavaScript, JScript
function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys.Process("PropertyGridSample");
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  // Modify some item values
  SelectListItem(Grid, "Appearance.Font.Name", "Tahoma");
  SelectListItem(Grid, "Layout.WindowState", "Maximized");
}
// Selects a new item from the list
function SelectListItem (Grid, FullLabel, Item)
{
  // Select the specified item
  ClickItem(Grid, FullLabel);
  // Open the dropdown list box
  Grid.Keys("[F4]");
  // Obtain the list box object
  var ListBox = Grid.GetPropertyGridView().DropDownListBox;
  ListBox = Sys.WindowFromHandle(ListBox.Handle);
  // Click the desired item
  ListBox.ClickItem (Item);
}
// Selects an item specified by its full label
function ClickItem (Grid, FullLabel)
{
  var ItemGroup, Labels, i;
  // Split the full label into parts
  Labels = FullLabel.split (".");
  // Walk down the items hierarchy
  ItemGroup = Grid;
  for (i=0; i<Labels.length-1; i++)
    ItemGroup = ItemGroup.wItems(Labels[i]);
  ItemGroup.ClickValue(Labels[i]);
}
Python
def Main ():
  # Obtain the grid object
  p = Sys.Process("PropertyGridSample")
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  # Modify some item values
  SelectListItem(Grid, "Appearance.Font.Name", "Tahoma")
  SelectListItem(Grid, "Layout.WindowState", "Maximized")
# Selects a new item from the list
def SelectListItem (Grid, FullLabel, Item):
  # Select the specified item
  ClickItem(Grid, FullLabel)
  # Open the dropdown list box
  Grid.Keys("[F4]")
  # Obtain the list box object
  ListBox = Grid.GetPropertyGridView().DropDownListBox
  ListBox = Sys.WindowFromHandle(ListBox.Handle)
  # Click the desired item
  ListBox.ClickItem (Item)
# Selects an item specified by its full label
def ClickItem (Grid, FullLabel):
  # Split the full label into parts
  Labels = FullLabel.split (".")
  # Walk down the items hierarchy
  ItemGroup = Grid
  for i in range(0, Labels.length-1):
    ItemGroup = ItemGroup.wItems[Labels[i]]
  ItemGroup.ClickValue(Labels[i])VBScript
Sub Main
  Dim p, Grid
  ' Obtain the grid object
  Set p = Sys.Process("PropertyGridSample")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  ' Modify some item values
  Call SelectListItem (Grid, "Appearance.Font.Name", "Tahoma")
  Call SelectListItem (Grid, "Layout.WindowState", "Maximized")
End Sub
' Selects a new value from the list
Sub SelectListItem (Grid, FullLabel, Item)
  Dim ListBox
  ' Open the dropdown list box
  Call ClickItem (Grid, FullLabel)
  Grid.Keys("[F4]")
  ' Obtain the list box object
  Set ListBox = Grid.GetPropertyGridView.DropDownListBox
  Set ListBox = Sys.WindowFromHandle(ListBox.Handle)
  ' Click the desired item
  ListBox.ClickItem(Item)
End Sub
' Selects an item specified by its full label
Sub ClickItem (Grid, FullLabel)
  Dim ItemGroup, Labels, i
  ' Split the full label into parts
  Labels = Split (FullLabel, ".")
  ' Access and select the item via its parent items
  Set ItemGroup = Grid
  For i = 0 To UBound(Labels)-1
    Set ItemGroup = ItemGroup.wItems(Labels(i))
  Next
  ItemGroup.ClickValue(Labels(i))
End Sub
DelphiScript
procedure SelectListItem (Grid, FullLabel, Item); forward;
procedure ClickItem (Grid, FullLabel); forward;
procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process ('PropertyGridSample');
  Grid := p.WinFormsObject('Form1').WinFormsObject('propertyGrid1');
  // Modify some item values
  SelectListItem(Grid, 'Appearance.Font.Name', 'Tahoma');
  SelectListItem(Grid, 'Layout.WindowState', 'Maximized');
end;
// Selects a new value from the list
procedure SelectListItem (Grid, FullLabel, Item);
var ListBox : OleVariant;
begin
  // Open the dropdown list box
  ClickItem(Grid, FullLabel);
  Grid.Keys('[F4]');
  // Obtain the list box object
  ListBox := Grid.GetPropertyGridView.DropDownListBox;
  ListBox := Sys.WindowFromHandle(ListBox.Handle);
  // Click the desired item
  ListBox.ClickItem (Item);
end;
// Selects an item specified by its full label
procedure ClickItem (Grid, FullLabel);
var ItemGroup, nLabels, i : OleVariant;
begin
  // Split the full label into parts
  aqString.ListSeparator := '.';
  nLabels := aqString.GetListLength (FullLabel);
  // Access and select the item via its parent items
  ItemGroup := Grid;
  for i := 0 to nLabels-2 do
    ItemGroup := ItemGroup.wItems[ aqString.GetListItem(FullLabel, i) ];
  ItemGroup.ClickValue( aqString.GetListItem(FullLabel, i) );
end;
C++Script, C#Script
function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys["Process"]("PropertyGridSample");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");
  // Modify some item values
  SelectListItem(Grid, "Appearance.Font.Name", "Tahoma");
  SelectListItem(Grid, "Layout.WindowState", "Maximized");
}
// Selects a new item from the list
function SelectListItem (Grid, FullLabel, Item)
{
  // Select the specified item
  ClickItem(Grid, FullLabel);
  // Open the dropdown list box
  Grid["Keys"]("[F4]");
  // Obtain the list box object
  var ListBox = Grid["GetPropertyGridView"]()["DropDownListBox"];
  ListBox = Sys["WindowFromHandle"](ListBox["Handle"]);
  // Click the desired item
  ListBox["ClickItem"](Item);
}
// Selects an item specified by its full label
function ClickItem (Grid, FullLabel)
{
  var ItemGroup, Labels, i;
  // Split the full label into parts
  Labels = FullLabel["split"](".");
  // Walk down the items hierarchy
  ItemGroup = Grid;
  for (i=0; i<Labels["length"]-1; i++)
    ItemGroup = ItemGroup["wItems"](Labels[i]);
  ItemGroup["ClickValue"](Labels[i]);
}
Note that in most cases, you can modify grid item values by typing the new value into the cell. For more information on inserting values in PropertyGrid, see Obtaining and Setting Item Values in Microsoft PropertyGrid.
See Also
Working With Microsoft PropertyGrid
Selecting Items in Microsoft PropertyGrid
Obtaining and Setting Item Values in Microsoft PropertyGrid
Copying and Pasting Item Values in Microsoft PropertyGrid

 View description
View description