This project is read-only.

Rows.Count is null for WPF's (custom?) DataGrid

Dec 1, 2012 at 2:53 PM
Edited Dec 1, 2012 at 2:59 PM


The WPF application I'm automating has DataGrid control. Almost all the times listView.Rows returns 0, despite of there are several rows. Number of Columns is correct. I tried to do the same using UIA, but the result was the same. So it's not a white problem. All the UI Spies show correct Rows/Columns numbers (!). Looks like for some reasons I get the state of the grid when it is just loaded, when rows count is 0. Also interesting, that 1 time both White and UIA were able to detect correct number of rows / columns after I just reopen the solution. But all next times after that this workaround has not helped..

Have anyone ever faced with such a problem in White / UIA ?


Window windowMain = UiaHelper.WaitObject(SprinterHelper.GetSprinterWindow);
ListView listTests = windowMain.Get<ListView>(ControlsHelper.Controls[C.RunMode_TestsListView]);
ListViewHeader header = listTests.Header;
ListViewColumn columnName = header.Column("Name");
int indexOfNameColumn = columnName.Index;
// Rows.Count is always == 0... But Spies show correct number.. ??
List<string> testNames = listTests.Rows.Select(r => r.Cells[indexOfNameColumn].Text).ToList();




Dec 1, 2012 at 4:04 PM

Sorry, my fault, there where 2 controls with the same properties, one visible, and other invisible. I have written an extension method which lacks in White to solve this problem:

public static T[] GetMultiple<T>(this UIItemContainer container, SearchCriteria criteria, VisibilityScope visibility) where T : UIItem
	IUIItem[] allItems = container.GetMultiple(criteria);
	switch (visibility)
		case VisibilityScope.All:
			return allItems.Cast<T>().ToArray();
		case VisibilityScope.Visible:
		case VisibilityScope.NotVisible:
			return allItems.Where(i => i.Visible == (visibility == VisibilityScope.Visible)).Cast<T>().ToArray();
	return null;