Combobox in datagridview

Aug 14, 2012 at 3:02 PM

First of all let me congratulate you guys for the great work on White. I've been having a good time using to tool yet.

As the title indicates, I'm having a problem using a combobox in a datagrid and would like to know if a such thing is possible (MS UIA limitations?) and if so how could I do it. I've made my own Datagridview wrapper class as I've realised early that the row proprety didn't work has I would have thought. Here's my code:


Public Class DataGridViewTable
        Inherits Table

        Private Const HeaderColAutomationElementFrench As String = "Ligne du haut"
        Private Const HeaderColAutomationElementEnglish As String = "Top Row"

        Private m_HeaderColAutomationElemName As String
        Private m_DataGridHasExtraHeader As Boolean

        Public Sub New(ByVal p_Table As Table)
            MyBase.New(p_Table.AutomationElement, p_Table.ActionListener)

            Dim ci As CultureInfo = CultureInfo.InstalledUICulture

            ' Set operation system language specific data.
            If ci.TwoLetterISOLanguageName = "en" Then
                m_HeaderColAutomationElemName = HeaderColAutomationElementEnglish
                Console.WriteLine("Operation System Language: English")
                m_HeaderColAutomationElemName = HeaderColAutomationElementFrench
                Console.WriteLine("Langage system d'op�ration: Fran�ais")
            End If

            ' The osiris build machine doesn't have the extra header column on datagrids.
            If Environment.MachineName.ToLower() = "osiris" Then
                m_DataGridHasExtraHeader = False
                m_DataGridHasExtraHeader = True
            End If
        End Sub

        ''' Gets a cell from the datagrid. Used to hide the automation element's logic.
        ''' The row to get the cell.
        ''' The column name to get the cell.
        ''' The cell object from the current datagridview
        Public Function GetCell(ByVal p_RowIndex As Integer, ByVal p_ColumnName As String) As TableCell
            Dim foundCell As TableCells

            ' Go threw Automation Elements to find the desired cell by it's automation ID.
            Dim curRow As TableRow = Me.Rows(p_RowIndex)
            Dim cellName As String = String.Format("{0} {1}", p_ColumnName, curRow.Name)
            Dim automationElemCollection As AutomationElementCollection = curRow.AutomationElement.FindAll(TreeScope.Descendants,
                                                                    New PropertyCondition(AutomationElement.NameProperty, cellName))

            foundCell = New TableCells(automationElemCollection, Me.Header, Me.ActionListener)
            Console.WriteLine(String.Format("Cell Automation name: {0}", cellName))

            Return foundCell.FirstOrDefault
        End Function

        ''' Gets a cell from the datagrid. Used to hide the automation element's logic.
        ''' The row to get the cell.
        ''' The column to get the cell.
        ''' The cell object from the current datagridview
        Public Function GetCell(ByVal p_RowIndex As Integer, ByVal p_ColumnIndex As Integer) As TableCell
            Dim columnHeaderName As String

            ' In some cases, the datagrid may have or not a square in the top left corner which is considered as the first column.
            If (m_DataGridHasExtraHeader) Then
                p_ColumnIndex += 1
            End If

            ' Find the column's name.
            Dim automationElemCollection As AutomationElementCollection = Me.AutomationElement.FindAll(TreeScope.Descendants,
                                                                    New PropertyCondition(AutomationElement.NameProperty, m_HeaderColAutomationElemName))
            Dim dgvHeader As New TableHeader(automationElemCollection.Item(0), Me.ActionListener)
            columnHeaderName = dgvHeader.Columns(p_ColumnIndex).Name

            Console.WriteLine(String.Format("{0} Column Name: {1}", p_ColumnIndex, columnHeaderName))

            Return GetCell(p_RowIndex, columnHeaderName)
        End Function

        Public Function GetComboboxCell(ByVal p_RowIndex As Integer, ByVal p_ColumnIndex As Integer) As White.Core.UIItems.ListBoxItems.Win32ComboBox
            Dim cellCombobox As White.Core.UIItems.ListBoxItems.Win32ComboBox
            Dim foundCell As TableCell = Me.GetCell(p_RowIndex, p_ColumnIndex)

            cellCombobox = New White.Core.UIItems.ListBoxItems.Win32ComboBox(foundCell.AutomationElement,
            'cellCombobox.Click() ' Click for White to have list items in memory.

            Return cellCombobox
        End Function
    End Class

And I do the above to try and select the first item of combobox:

Public Sub SelectProductName(ByVal p_ItemIndex As Integer)
            Dim dgvCmboBox As White.Core.UIItems.ListBoxItems.ComboBox = GetSuggestedProductionDGV().GetComboboxCell(0, 1)
            ' Select first product from combobox.
       End Sub
Private Function GetSuggestedProductionDGV() As DataGridViewTable
            Return New DataGridViewTable(m_Form.Get(Of White.Core.UIItems.TableItems.Table)(SearchCriteria.ByAutomationId("dgvJobs")))
        End Function

And I assure the gotten cell is a combobox and has data in it.

Aug 14, 2012 at 3:28 PM

Oh forgot to metion, I have the error on:


where I get an InvalidIndex exception.
Aug 15, 2012 at 6:41 AM


first of all, have a look on the combobox in UIAVerify or UISpy (without clicking on it) I would think the combobox does not have any elements in the Item List)

so your first step should be


click on ComboBox to expand item list,

click everywhere else (I use the title bar),

try now