Selecting Property Tabs in Microsoft PropertyGrid

The PropertyGrid control supports multiple property views: alphabetical, categorized, etc. To switch between different views, the user can select the corresponding button on the grid’s embedded toolbar. It is also possible to switch between the property tabs programmatically by using the grid’s internal PropertySort property



Below I will explain how you can implement both approaches in TestComplete scripts.

Simulating Toolbar Button Clicks


The PropertyGrid control has an embedded toolbar that can be used to switch between the property views. The toolbar is visible if the grid’s ToolbarVisible property is True. If so, you can obtain the object corresponding to the toolbar control and then select the needed property tab by simulating a click on the corresponding toolbar button.


The object that corresponds to the grid toolbar appears as the grid’s child object, and you can address it using the WinFormsObject method. The notation used to address the toolbar depends on the PropertyGrid control version used in the application:



  • for applications created in Microsoft Visual Studio .NET:

    grid.WinFormsObject("GridToolBar", "")


  • for applications created in Microsoft Visual Studio 2005:

    grid.WinFormsObject("ToolStrip", "PropertyGridToolBar")




To simulate a click on 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 position within the toolbar, starting from 0: the position of the Categorized button is 0, the Alphabetical button - 1, and so on. For Visual Studio 2005 applications, it is also possible to specify the toolbar item by its caption – “Categorized”, “Alphabetical”, and so on.


Below is an example that demonstrates how you can switch between PropertyGrid tabs by clicking toolbar buttons:






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. You can set this property to one of the following values: “NoSort” (0), “Alphabetical” (or 1), “Categorized” (or 2) or “CategorizedAlphabetical” (or 3; in fact, it is the same as “Categorized”). This will make the corresponding property tab selected in the grid.



The following code snippet demonstrates how you can use the PropertySort property to change the grid’s active tab:




Close

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

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