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);