Reg: Select row based on index of DatagridView using automation element


  • Hi,

    please help in finding how to Select row based on index of DatagridView using automation element or UIframework.

    also how to find the total number of rows in the Datagrid using automation element



    Regards, Gomko

    Saturday, August 17, 2013 8:46 AM

All replies

  • This works for me on DataGridView from WindowsForms library using managed UIAutomation API.

    Lets assume that you already have a datagrid object loaded in grid variable.

    List<AutomationElement> rows = new List<AutomationElement>();
    // gathers all elements with Row string in its name (they are detected as Custom controls in UIA and haven't seen any better property to use)
    foreach (AutomationElement element in grid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom)))
        if (element.Current.Name.Contains("Row"))
    // header inside the row control has invoke pattern which can be used to select row
    AutomationElement header = rows[0].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Header));
    InvokePattern pattern = header.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;


    Monday, August 19, 2013 1:05 PM