This topic explains how you can access and refer to items displayed in the PropertyGrid control:
|  | 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  | 
Using MicrosoftPropertyGrid Properties
Methods and properties of the MicrosoftPropertyGrid object let you work with top-level grid items. To access child items of a specific item, use the wItems property. It returns the PropertyGridItemGroup object that provides access to a group of child items. In a similar way, you can access grandchild items using the wItems(…).wItems(…) notation, and so on. The wItemCount property lets you determine the number of top-level items in the PropertyGrid or the number of items in a particular group. You can use this property, for example, to iterate through grid items.
The following example demonstrates how you can perform various actions over PropertyGrid items:
JavaScript, JScript
function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys.Process("PropertyGridSample");
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  // Set the new "Appearance.Font.Name" item value
  Grid.wItems("Appearance").Expand("Font");
  Grid.wItems("Appearance").wItems("Font").ClickValue("Name");
  Grid.Keys("^a[Del]" + "Tahoma" + "[Enter]");
  // Toggle the "Appearance.Font.Bold" value
  Grid.wItems("Appearance").wItems("Font").DblClickLabel("Bold");
}
Python
def Main ():
  # Obtain the grid object
  p = Sys.Process("PropertyGridSample")
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  # Set the new "Appearance.Font.Name" item value
  Grid.wItems["Appearance"].Expand("Font")
  Grid.wItems["Appearance"].wItems["Font"].ClickValue("Name")
  Grid.Keys("^a[Del]" + "Tahoma" + "[Enter]")
  # Toggle the "Appearance.Font.Bold" value
  Grid.wItems["Appearance"].wItems["Font"].DblClickLabel("Bold")VBScript
Sub Main
  Dim p, Grid
  ' Obtain the grid object
  Set p = Sys.Process("PropertyGridSample")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  ' Set the new "Appearance.Font.Name" item value
  Grid.wItems("Appearance").Expand("Font")
  Grid.wItems("Appearance").wItems("Font").ClickValue("Name")
  Grid.Keys("^a[Del]" & "Tahoma" & "[Enter]")
  ' Toggle the "Appearance.Font.Bold" value
  Grid.wItems("Appearance").wItems("Font").DblClickLabel("Bold")
End Sub
DelphiScript
procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('PropertyGridSample');
  Grid := p.WinFormsObject('Form1').WinFormsObject('propertyGrid1');
  // Set the new 'Appearance.Font.Name' item value
  Grid.wItems['Appearance'].Expand('Font');
  Grid.wItems['Appearance'].wItems['Font'].ClickValue('Name');
  Grid.Keys('^a[Del]' + 'Tahoma' + '[Enter]');
  // Toggle the 'Appearance.Font.Bold' value
  Grid.wItems['Appearance'].wItems['Font'].DblClickLabel('Bold');
end;
C++Script, C#Script
function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys["Process"]("PropertyGridSample");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");
  // Set the new "Appearance.Font.Name" item value
  Grid["wItems"]("Appearance")["Expand"]("Font");
  Grid["wItems"]("Appearance")["wItems"]("Font")["ClickValue"]("Name");
  Grid["Keys"]("^a[Del]" + "Tahoma" + "[Enter]");
  // Toggle the "Appearance.Font.Bold" value
  Grid["wItems"]("Appearance")["wItems"]("Font")["DblClickLabel"]("Bold");
}
Using PropertyGrid Internal Members
In certain cases, it can be useful to work with PropertyGrid items using the control’s internal properties and methods. For instance, this way you can check whether the item’s description is specified without selecting this item in the grid.
You can obtain a collection of top-level items of the PropertyGrid control using the grid’s GetPropEntries method. To obtain a specific item from the collection, use one of the overloaded versions of the Item property:
- Item (Index)- Returns an item by its zero-based index. The total number of items in the collection is specified by the- Countproperty.
- Item_2 (Name)- Returns an item by its label (for example, “Font” or “Text”).
To access child items of a specific item, use the item’s GridItems property. In a similar way, you can iterate through the obtained collection using the Count property and obtain grandchild items using the Item and Item_2 properties.
Below is an example that demonstrates how you can access and work with PropertyGrid items using the grid’s internal properties and methods.
Example
JavaScript
function Main ()
{
  var p, Grid, Item;
  // Obtain the grid object
  p = Sys.Process("PropertyGridSample");
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  // Get the "Appearance.Font" item description
  Item = GetItem(Grid, "Appearance.Font");
  Log.Message (Item.PropertyDescription.OleValue);
}
function GetItem (Grid, FullLabel)
{
  var Labels, Coll, Item;
  // Split the full label into parts
  Labels = FullLabel.split(".");
  // Get the top-level grid items
  Coll = Grid.GetPropEntries();
  // Walk down the item hierarchy
  for (let i=0; i<Labels.length; i++)
  {
    // Obtain the item by its label
    Item = Coll.Item_2 (Labels[i]);
    if (strictEqual(Item, null))
      return null;  // The item with the specified label is not found
    // Get child items of the current item
    Coll = Item.GridItems;
  }
  return Item;
}
JScript
function Main ()
{
  var p, Grid, Item;
  // Obtain the grid object
  p = Sys.Process("PropertyGridSample");
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1");
  // Get the "Appearance.Font" item description
  Item = GetItem(Grid, "Appearance.Font");
  Log.Message (Item.PropertyDescription.OleValue);
}
function GetItem (Grid, FullLabel)
{
  var Labels, Coll, Item, i;
  // Split the full label into parts
  Labels = FullLabel.split(".");
  // Get the top-level grid items
  Coll = Grid.GetPropEntries();
  // Walk down the item hierarchy
  for (i=0; i<Labels.length; i++)
  {
    // Obtain the item by its label
    Item = Coll.Item_2 (Labels[i]);
    if (Item == null)
      return null;  // The item with the specified label is not found
    // Get child items of the current item
    Coll = Item.GridItems;
  }
  return Item;
}
Python
def Main ():
  # Obtain the grid object
  p = Sys.Process("PropertyGridSample")
  Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  # Get the "Appearance.Font" item description
  Item = GetItem(Grid, "Appearance.Font")
  Log.Message (Item.PropertyDescription.OleValue)
def GetItem (Grid, FullLabel):
  # Split the full label into parts
  Labels = FullLabel.split(".")
  # Get the top-level grid items
  Coll = Grid.GetPropEntries()
  # Walk down the item hierarchy
  for i in range(0, Labels.length-1):
    # Obtain the item by its label
    Item = Coll.Item_2 [Labels[i]]
    if (Item == None):
      return None # The item with the specified label is not found
    # Get child items of the current item
    Coll = Item.GridItems
  return ItemVBScript
Sub Main
  Dim p, Grid, Item
  ' Obtain the grid object
  Set p = Sys.Process ("PropertyGridSample")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("propertyGrid1")
  ' Get the "Appearance.Font" item description
  Set Item = GetItem(Grid, "Appearance.Font")
  Log.Message (Item.PropertyDescription.OleValue)
End Sub
Function GetItem (Grid, FullLabel)
  Dim Labels, Coll, Item, i
  ' Split the full label into parts
  Labels = Split (FullLabel, ".")
  ' Get the top-level grid items
  Set Coll = Grid.GetPropEntries
  ' Walk down the item hierarchy
  For i=0 To UBound(Labels)
    ' Obtain the item by its label
    Set Item = Coll.Item_2 (Labels(i))
    If Item Is Nothing Then
      Set GetItem = Nothing ' The item with the specified label is not found
      Exit Function
    End If
    ' Get child items of the current item
    Set Coll = Item.GridItems
  Next
  Set GetItem = Item 
End Function
DelphiScript
function GetItem (Grid, FullLabel);
var nLabels, Coll, Item, i : OleVariant;
begin
  // Get the top-level grid items
  Coll := Grid.GetPropEntries;
  // Walk down the item hierarchy
  aqString.ListSeparator := '.'; 
  nLabels := aqString.GetListLength (FullLabel); 
  for i:=0 to nLabels-1 do
  begin
    // Obtain the item by its label
    Item := Coll.Item_2 (aqString.GetListItem (FullLabel, i));
    if Item = nil then
      Result := nil;  // The item with the specified label is not found
    // Get child items of the current item
    Coll := Item.GridItems;
  end;
  Result := Item; 
end;
procedure Main;
var p, Grid, Item : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('PropertyGridSample');
  Grid := p.WinFormsObject('Form1').WinFormsObject('propertyGrid1');
  // Get the "Appearance.Font" item description
  Item := GetItem(Grid, 'Appearance.Font');
  Log.Message(Item.PropertyDescription.OleValue);
end;
C++Script, C#Script
function Main ()
{
  var p, Grid, Item;
  // Obtain the grid object
  p = Sys["Process"]("PropertyGridSample");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("propertyGrid1");
  // Get the "Appearance.Font" item description
  Item = GetItem(Grid, "Appearance.Font");
  Log["Message"](Item["PropertyDescription"]["OleValue"]);
}
function GetItem (Grid, FullLabel)
{
  var Labels, Coll, Item, i;
  // Split the full label into parts
  Labels = FullLabel["split"](".");
  // Get the top-level grid items
  Coll = Grid["GetPropEntries"]();
  // Walk down the item hierarchy
  for (i=0; i<Labels["length"]; i++)
  {
    // Obtain the item by its label
    Item = Coll["Item_2"](Labels[i]);
    if (Item == null)
      return null;  // The item with the specified label is not found
    // Get child items of the current item
    Coll = Item["GridItems"];
  }
  return Item;
}
See Also
Working With Microsoft PropertyGrid
Getting the Focused Item in Microsoft PropertyGrid
Obtaining and Setting Item Values in Microsoft PropertyGrid
wItems Property (Specific to PropertyGrid Controls)
wItemCount Property (Specific to PropertyGrid Controls)

 View description
View description