Skip to main content

ListView and TreeView Controls

These methods use Windows Automation operate on Automation Elements with the property ControlType.List or ControlType.TreeItem. They may behave differently to similar methods on the WinDriver Control object, which only operate on SysTreeView32 and SysListView32 window classes

ListView

MethodDescription
GetListItemCountReturn the number of items in the List
GetListItemLocationReturn the location coordinates of the item with the given index number or name

TreeView

MethodDescription
GetTreeViewItemCountReturn the number of visible items in the Tree
GetTreeItemLocationReturn the location coordinates of the item with the given name
GetTreeItemRectangeReturn the rectangle enclosing the item
ExpandTreeItemReturn the location of the item
SelectTreeItemSet the item to the selected state
GetTreeItemTextGet the text of the item for the given index number

Example

AutomationControl runWindow = FindTopAutomationWindow("Two ListBox DragDrop Demo");
IList<AutomationControl> lists = runWindow.FindControls(ControlType.List); //finds all list controls by control type
runWindow.ToControl().ShowWindow(); //makes sure that window is visible
runWindow.SetForegroundWindow(); //makes sure that window is in foreground and active
foreach (AutomationControl list in lists) //gets the number of items each list holding
{
int n = list.GetListItemCount();
WriteMessage("List items:"+n);
}

AutomationControl window = FindTopAutomationWindow("Demo App (multiple selection treeview");
window.ToControl().ShowWindow(ShowWindowCodes.SW_MAXIMIZE); //maximizes window if minimized
window.SetForegroundWindow();
AutomationControl tree = window.FindControl(ControlType.Tree); //gets tree control
tree.ExpandTreeItem(tree.GetTreeItemText(0)); //expands tree
Point p = tree.GetTreeItemLocation(tree.GetTreeItemText(0)); //close tree. This method can be used for both, to expand and to close
Mouse.DoubleLeftClick(p);