Reading data from Windows Datagridview control

Mar 24, 2010 at 8:02 AM
Edited Mar 26, 2010 at 8:07 AM

How can we read the data from a windows Datagridview? When i tried this code the I always get rowcount as 0. Any code snippet or link to a website would be helpful. This is the coed that I tried..

Table   tab = window.Get<Table>("gdvAcademics");

White.Core.UIItems.TableItems.

TableRows  grdRows = tab.Rows; 

Console.WriteLine(grdRows.Count.ToString());

Mar 26, 2010 at 8:06 AM

On Similar lines, I am facing issues reading content from Listview control. Given below is the code snippet. The Console.writeline statment in the first foreach loop prints "ListViewRow. AutomationId:, Name:, ControlType:dataitem, FrameworkId:WinForm" which looks correct but the second foreach loop does not print any data. Any suggestions?

            Application application = Application.Launch(@"SimpleTest.exe");
            White.Core.UIItems.WindowItems.Window window = application.GetWindow("Form1");

            White.Core.UIItems.ListView lvw = window.Get<White.Core.UIItems.ListView>("listView1");

            foreach (ListViewRow row in lvw.Rows)
            {
                Console.WriteLine(row.ToString());   
                foreach (White.Core.UIItems.ListViewCell lvwCell in row.Cells)
                {
                    Console.WriteLine(lvwCell.Text);
                }


            }
 

Mar 26, 2010 at 8:13 AM

what says UISpy or UIAVerify looking on this ListView?

have you tried LogStructure() on ListView element?

 

Mar 26, 2010 at 8:37 AM

Both of them display the controls as expected..  Is there anyway , I can pass you the AUT and the test code?

Mar 26, 2010 at 2:48 PM

Is this a WPF DataGrid (ListView)?

May it happen that the cells contain custom elements?

Have you tried to output any intermediate info, like

         Console.WriteLine("Cells count: {0}", lvw.Rows.Count);

         Console.WriteLine("Cells count: {0}", row.Cells.Count);

I wonder why do you use full names like  White.Core.UIItems.ListView lvw, but just a type here: 

ListViewRow row

 

Mar 26, 2010 at 6:21 PM

It is a normal Windows Form listview Control. I am able to loop through the rows but am unable to loop within each row i.e. the cell part.

And yes, thanks for observing the long name, I shall add the using statements and make the statements a little terse. If possible try and create a simple .Net windows app  drop a data grid view and list view and check if you can read the rows and columns. if successful then please post the code.

Mar 29, 2010 at 10:40 AM
Edited Mar 29, 2010 at 10:42 AM

deepban74, I do not have any problems with ListView. All cells are enumerating well. Probably you have not specified columns for Details view mode.

Here is my code:

private void Form1_Load(object sender, EventArgs e)
{
  listView1.Items.Add(new ListViewItem(new string[] { "item1", "foo"}));
 
listView1.Items.Add(new ListViewItem(new string[] { "item2", "blablabla" }));
}

And a test similar to yours:

 

Application app = Application.Launch("WindowsApplication1.exe");
Window window = app.GetWindow("Form1");
ListView listView = window.Get<ListView>("listView1");foreach(ListViewRow row in  listView.Rows)
{
 
Console.WriteLine(row.ToString());
 
foreach(ListViewCell cell in row.Cells)
   
Console.WriteLine(cell.Text);
}

BTW, DataGridView also is not testable with White. I don't know why, but it cannot find any rows.

 

Coordinator
Apr 10, 2010 at 3:58 PM

have you looked at number 3 here.

http://white.codeplex.com/wikipage?title=Other%20questions&referringTitle=Home

 

Apr 16, 2010 at 12:02 PM

No. It is not related to the Apartment  states.

When I loaded data from a database in the datagrid i as able to access the rows. trying to  resolve the issue with listview.