Share via


UI Automation Support for the DataGrid Control Type

This topic provides information about Microsoft UI Automation support for the DataGrid control type.

The DataGrid control type lets a user easily work with items that contain data or automation elements presented in columns or rows. Data grid controls have rows of items and columns of information about those items. A List View control in Microsoft Vista Explorer is an example that supports the DataGrid control type.

The following sections define the required UI Automation tree structure, properties, control patterns, and events for the DataGrid control type. The UI Automation requirements apply to all data grid controls, whether Microsoft Windows Presentation Foundation (WPF), Microsoft Win32, or Windows Forms.

This topic contains the following sections.

  • Required UI Automation Tree Structure
  • Required UI Automation Properties
  • Required UI Automation Control Patterns
  • Required UI Automation Events
  • DataGrid Control Type Example
  • Related Topics

Required UI Automation Tree Structure

The following table depicts the control view and the content view of the UI Automation tree that pertains to data grid controls and describes what can be contained in each view. For more information about the UI Automation tree, see UI Automation Tree Overview.

Control View Content View
  • DataGrid
    • Header (0, 1, or 2)
      • HeaderItem (number of columns or rows)
    • DataItem (0 or more; can be structured in a hierarchy)
  • DataGrid
    • DataItem (0 or more; can be structured in a hierarchy)

Required UI Automation Properties

The following table lists the UI Automation properties whose value or definition is especially relevant to the DataGrid control type. For more information about UI Automation properties, see UI Automation Properties for Clients.

UI Automation Property Value Notes
UIA_AutomationIdPropertyId See notes. The value of this property needs to be unique across all controls in an application.
UIA_BoundingRectanglePropertyId See notes. The outermost rectangle that contains the whole control.
UIA_ClickablePointPropertyId See notes. Supported if there is a bounding rectangle. If not every point within the bounding rectangle is clickable, and you perform specialized hit testing, override and provide a clickable point.
UIA_ControlTypePropertyId DataGrid This value is the same for all UI frameworks.
UIA_IsContentElementPropertyId TRUE The value of this property must always be TRUE. This means that the data grid control must always be in the content view of the UI Automation tree.
UIA_IsControlElementPropertyId TRUE The value of this property must always be TRUE. This means that the data grid control must always be included in the control view of the UI Automation tree.
UIA_IsKeyboardFocusablePropertyId See notes. If the control can receive keyboard focus, it must support this property.
UIA_LabeledByPropertyId See notes. If there is a static text label, this property must expose a reference to that control.
UIA_LocalizedControlTypePropertyId See notes. Localized string corresponding to the DataGrid control type. The default value is "data grid" for en-US or English (United States).
UIA_NamePropertyId See notes. The data grid control typically gets the value for its Name property from a static text label. If there is not a static text label an application developer must assign a value to for the Name property. The value of the Name property must never be the textual contents of the edit control.

Required UI Automation Control Patterns

The following table lists the UI Automation control patterns required to be supported by all data grid controls. For more information on control patterns, see UI Automation Control Patterns Overview.

Control Pattern/Pattern Property Support/Value Notes
IGridProvider Yes The data grid control itself always supports the Grid control pattern because the items that it contains have metadata that is laid out in a grid.
IScrollProvider Depends The ability to scroll the data grid depends on content and whether scroll bars are present.
ISelectionProvider Depends The ability to select the data grid depends on content.
ITableProvider Depends A data grid control that has a header should support the Table control pattern.

Data items within the data grid containers will support at a minimum:

  • SelectionItem control pattern (if the data grid is selectable)
  • ScrollItem control pattern (if the data grid is scrollable)
  • GridItem control pattern
  • TableItem control pattern (if the data grid has a header)

Required UI Automation Events

The following table lists the UI Automation events that data grid controls are required to support. For more information on events, see UI Automation Events Overview.

UI Automation Event Notes
UIA_AutomationFocusChangedEventId None
UIA_BoundingRectanglePropertyId property-changed event. None
UIA_IsEnabledPropertyId property-changed event. If the control supports the IsEnabled property, it must support this event.
UIA_IsOffscreenPropertyId property-changed event. If the control supports the IsOffscreen property, it must support this event.
UIA_LayoutInvalidatedEventId None
UIA_StructureChangedEventId None
UIA_MultipleViewCurrentViewPropertyId property-changed event. If the control supports the CurrentView property of the MultipleView control pattern, it must support this event.
UIA_ScrollHorizontallyScrollablePropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_ScrollHorizontalScrollPercentPropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_ScrollHorizontalViewSizePropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_ScrollVerticalScrollPercentPropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_ScrollVerticallyScrollablePropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_ScrollVerticallyViewSizePropertyId property-changed event. If the control supports the Scroll control pattern, it must support this event.
UIA_Selection_InvalidatedEventId None

DataGrid Control Type Example

The following image illustrates a List View control that implements the DataGrid control type.

List View control with DataGrid control type

The control view and the content view of the UI Automation tree that pertains to the List View control is displayed below. The control patterns for each automation element are shown in parentheses.

UI Automation Tree - Control View UI Automation Tree - Content View
DataGrid (Sort, Table, Selection, Grid)
  • Header
    • HeaderItem "Name" (Invoke)
    • HeaderItem "Date Modified" (Invoke)
    • HeaderItem "Size" (Invoke)
  • Group "Contoso" (TableItem, GridItem, SelectionItem, Table*, Grid*)
    • DataItem "Accounts Receivable.doc" (SelectionItem, Invoke, TableItem*, GridItem*)
    • DataItem "Accounts Payable.doc" (SelectionItem, Invoke, TableItem*, GridItem*)
DataGrid (Table, Grid, Selection)
  • Group "Contoso" (TableItem, GridItem, SelectionItem, Table*, Grid*)
    • DataItem "Accounts Receivable.doc" (SelectionItem, Invoke, TableItem*, GridItem*)
    • DataItem "Accounts Payable.doc" (SelectionItem, Invoke, TableItem*, GridItem*)

*The preceding example shows a DataGrid that contains multiple levels of controls. The Group ("Contoso") control contains two DataItem controls ("Accounts Receivable.doc" and "Accounts Payable.doc"). A DataGrid/GridItem pair is independent of a pair at another level. The DataItem controls under a Group can also be exposed as a ListItem control type, enabling them to be presented more clearly as selectable objects, rather than as simple data elements. This example does not include the sub-elements of the grouped data items. For another example of multiple levels of controls, see DataItem Control Type Example.