Implementing the UI Automation Grid Control Pattern


This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.

This topic introduces guidelines and conventions for implementing IGridProvider, including information about properties, methods, and events. Links to additional references are listed at the end of the overview.

The GridPattern control pattern is used to support controls that act as containers for a collection of child elements. The children of this element must implement IGridItemProvider and be organized in a two-dimensional logical coordinate system that can be traversed by row and column. For examples of controls that implement this control pattern, see Control Pattern Mapping for UI Automation Clients.

Implementation Guidelines and Conventions

When implementing the Grid control pattern, note the following guidelines and conventions:

  • Grid coordinates are zero-based with the upper left (or upper right cell depending on locale) having coordinates (0, 0).

  • If a cell is empty, a UI Automation element must still be returned in order to support the ContainingGrid property for that cell. This is possible when the layout of child elements in the grid is similar to a ragged array (see example below).

Windows Explorer view showing ragged layout. Example of a Grid Control with Empty Coordinates

  • A grid with a single item is still required to implement IGridProvider if it is logically considered to be a grid. The number of child items in the grid is immaterial.

  • Hidden rows and columns, depending on the provider implementation, may be loaded in the UI Automation tree and therefore will be reflected in the RowCount and ColumnCount properties. If the hidden rows and columns have not yet been loaded, they should not be counted.

  • IGridProvider does not enable active manipulation of a grid; ITransformProvider must be implemented to enable this functionality.

  • Use a StructureChangedEventHandler to listen for structural or layout changes to the grid such as cells that have been added, removed, or merged.

  • Use a AutomationFocusChangedEventHandler to track traversal through the items or cells of a grid.

Required Members for IGridProvider

The following properties and methods are required for implementing the IGridProvider interface.

Required members Type Notes
RowCount Property None
ColumnCount Property None
GetItem Method None

This control pattern has no associated events.


Providers must throw the following exceptions.

Exception type Condition
ArgumentOutOfRangeException GetItem

- If the requested row coordinate is larger than the RowCount or the column coordinate is larger than the ColumnCount.
ArgumentOutOfRangeException GetItem

- If either of the requested row or column coordinates is less than zero.

See also