Expanding and Collapsing Rows in Microsoft PropertyGrid
Test and Monitor | Posted March 21, 2007

The PropertyGrid control displays its entries in a hierarchical form; properties may be displayed under categories, they may have nested properties, and so on. The users can expand the categories and rows to view their nested rows, or collapse them in order to simplify the grid view. In this post, I'll explain how you can expand and collapse PropertyGrid rows from scripts.

Simulating Keyboard Shortcuts

You can expand and collapse PropertyGrid rows using the corresponding keyboard shortcuts. For example, you can use the Right Arrow or Ctrl+Plus shortcut to expand the selected row, and the Left Arrow or Ctrl+Minus shortcut to collapse the selected row. To simulate these shortcuts, use the TestComplete’s Keys action applied to the grid control.

The example below illustrates how you can simulate the expand/collapse row keystrokes in the PropertyGrid. The example contains the following routines:

  • Main -- the main routine. It obtains the grid control and then expands and collapses the “Appearance.Font” row.

  • The ExpandRow and CollapseRow routines are used to expand and collapse the grid row. The Grid parameter specifies the tested PropertyGrid control, and FullLabel specifies the grid row’s full label (e.g. “Appearance.Font.Name”). Both routines call the SetRowExpanded routine to change the row’s expanded state.

  • SetRowExpanded -- a helper routine used to set the expanded state of the specified grid row.

  • GetItem -- a helper function that returns the grid row object by its full label. You can find more information on this function in Accessing Microsoft PropertyGrid Rows.

  • IsNullValue -- a helper function that checks whether the specified value is the null value.

Using the PropertyGrid Native Members

The PropertyGrid control and its relative objects include special properties and methods that let you toggle the row’s expanded state. To check or change the expanded state of a particular grid row, you can use its Expanded property.

Below is an example that demonstrates how you can use this property in scripts. This example differs from the previous one only in implementation of the ExpandRow and CollapseRow routines. To run this example successfully, you need to include the GetItem and IsNullValue functions used in the previous example in your script.

The PropertyGrid control also has the ExpandAllGridItems and CollapseAllGridItems methods that let you expand or collapse all grid rows at once. The following code snippet shows how you can use them in scripts:


By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox