Winforms datagridview problems (again)

May 5, 2011 at 10:14 AM

Hello. I have read several reports about datagridview problems and possible solutions, but none of these solutions help me.

I created a console application and add the following function to it

    

    public void Test()
        {
            var exeFilePath = Environment.CurrentDirectory + @"\..\..\..\Tidy.UI\bin\Debug\Tidy.UI.exe";

            var textFileToRead = Path.Combine(Environment.CurrentDirectory, @"TestData\SimpleTextFileToRead.txt");

            Application application = Application.Launch(exeFilePath);

            Window form1 = application.GetWindow("Form1", InitializeOption.NoCache);
            var menuBar = form1.MenuBar;
            var openMenuItem = menuBar.MenuItem("File", "Open");
            openMenuItem.Click();
            var openFileDialog = form1.ModalWindow("Open");
            var openFileDialogComboBox = openFileDialog.Get<ComboBox>();
            openFileDialogComboBox.EditableText = textFileToRead;
            var openButton = openFileDialog.Get<Button>("Open");
            openButton.Click();

            var dataGridView = form1.Get<Table>("dgvMain");
            Console.WriteLine(dataGridView.Rows.Count);

            application.Kill();
            Console.ReadKey();
        }

dataGridView.Rows.Count is 0 in this case even though I see 2 rows

here's

 dataGridView.LogStructure():

AutomationId: dgvMain
ControlType: ControlType.Table
Name: DataGridView
HelpText:
Bounding rectangle: 33,79,284,238
ClassName: WindowsForms10.Window.8.app.0.329445b_r13_ad1
IsOffScreen: False
FrameworkId: WinForm
ProcessId: 5772


    AutomationId: 1708012
    ControlType: ControlType.Pane
    Name: Horizontal scrollbar
    HelpText:
    Bounding rectangle: 34,299,282,17
    ClassName: WindowsForms10.SCROLLBAR.app.0.329445b_r13_ad1
    IsOffScreen: False
    FrameworkId: WinForm
    ProcessId: 5772


    AutomationId:
    ControlType: ControlType.Custom
    Name: Top Line
    HelpText:
    Bounding rectangle: 34,80,282,34
    ClassName:
    IsOffScreen: False
    FrameworkId:
    ProcessId: 5772

    System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: Left header cell
        HelpText: DataGridViewTopLeftHeaderCell(DataGridViewColumnHeaderCell)
        Bounding rectangle: 34,80,41,34
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: Name
        HelpText: DataGridViewColumnHeaderCell(DataGridViewHeaderCell)
        Bounding rectangle: 75,80,100,34
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: Address
        HelpText: DataGridViewColumnHeaderCell(DataGridViewHeaderCell)
        Bounding rectangle: 175,80,100,34
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: BirthPlace
        HelpText: DataGridViewColumnHeaderCell(DataGridViewHeaderCell)
        Bounding rectangle: 275,80,100,34
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

    AutomationId:
    ControlType: ControlType.Custom
    Name: Line 0
    HelpText:
    Bounding rectangle: 34,114,282,22
    ClassName:
    IsOffScreen: False
    FrameworkId:
    ProcessId: 5772

    System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: Line 0
        HelpText: DataGridViewRowHeaderCell(DataGridViewHeaderCell)
        Bounding rectangle: 34,114,41,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: Name line 0
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 75,114,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: Address line 0
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 175,114,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: BirthPlace line 0
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 275,114,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

    AutomationId:
    ControlType: ControlType.Custom
    Name: Line 1
    HelpText:
    Bounding rectangle: 34,136,282,22
    ClassName:
    IsOffScreen: False
    FrameworkId:
    ProcessId: 5772

    System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Header
        Name: Line 1
        HelpText: DataGridViewRowHeaderCell(DataGridViewHeaderCell)
        Bounding rectangle: 34,136,41,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: Name line 1
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 75,136,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: Address line 1
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 175,136,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: BirhtPlace line 1
        HelpText: DataGridViewTextBoxCell(DataGridViewCell)
        Bounding rectangle: 275,136,100,22
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern
        System.Windows.Automation.ValuePattern

    AutomationId:
    ControlType: ControlType.ScrollBar
    Name: Horizontal Scrollbar
    HelpText:
    Bounding rectangle: 34,299,282,17
    ClassName:
    IsOffScreen: False
    FrameworkId:
    ProcessId: 5772

    System.Windows.Automation.ValuePattern

        AutomationId:
        ControlType: ControlType.Button
        Name: Left Column
        HelpText:
        Bounding rectangle: 34,299,17,17
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern

        AutomationId:
        ControlType: ControlType.Custom
        Name: Position
        HelpText:
        Bounding rectangle: 51,299,199,17
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772


        AutomationId:
        ControlType: ControlType.Button
        Name: Right page
        HelpText:
        Bounding rectangle: 250,299,49,17
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

        System.Windows.Automation.InvokePattern

        AutomationId:
        ControlType: ControlType.Button
        Name: Right column
        HelpText:
        Bounding rectangle: 299,299,17,17
        ClassName:
        IsOffScreen: False
        FrameworkId:
        ProcessId: 5772

 

May 5, 2011 at 10:42 AM

Maybe the problem is that all cells are ControlType.Custom and not Cell

So you have to write your own helper to get lines from table and a helper get cells from line

Throndorin

May 5, 2011 at 11:50 AM

Thanks for the answer. Did anyone face the same problem? Could you, please, share the code that can deal with this case. Thanks in advance!

Nov 4, 2013 at 8:47 AM
I have run into same issue. It seems to recognize dataGridView as ControlType.Table but the rows are identified as ControlType.Custom and there is no Automation ID value.

Has anyone found a workaround for this?