I am trying to write some methods to locate a folder in a treeview. Basically I want to pass the following string to my function and then it should one by one open the folders until it reaches the final folder:
Code: Select all
LocateFolderInLeftHandPane(@"My Computer\C:\Program Files\Common Files\Adobe\Color\Profiles\Recommended")
My methods are:
Code: Select all
public void LocateFolderInLeftHandPane(string path)
{
// Break down the path
string[] folderList = path.Split(@"\".ToCharArray());
// Get the left hand side pane
Control control = mSelf.FindControlId(ControlNames.FileSelectorDialog.AV_FILE_SELECTOR_TREEVIEW_CONTROLID);
// Get the treeview
TreeView tw = new TreeView(control.Handle);
// Get the element for the treeview
Element treeElement = tw.Element.FindChild(Role.Outline);
// Locate
Locate(tw, treeElement, folderList, 0);
}
Code: Select all
private void Locate(TreeView treeView, Element folder, string[] folderList, int index)
{
// If we have reached the last folder in the fields array then exit
if (index > folderList.Length - 1)
{
return;
}
// Get the count for the children
int childCount = folder.GetChildCount;
// Traverse the tree
Element node = null;
for (int i = 0; i < childCount; i++)
{
// Get the node
node = folder.GetChild(i);
// If the specified folder is found then expand it
if(node.Name.IndexOf(folderList[index]) > -1)
{
// Expand
TreeNodeExpand(node);
// Increment to get the name of the next folder
index++;
// Find the current folder
node = treeView.Element.FindChild(Role.Outline);
// Break out of the loop
break;
}
}
// Recurse
Locate(treeView, node, folderList, index);
}
Code: Select all
protected void TreeNodeExpand(Element folder)
{
// Check to see if the node is collapsed then expand it
if ((folder.State & State.Collapsed) != 0)
{
// Double click the folder
ElementDoubleClick(folder);
// Wait for it to get expanded
while ((folder.State & State.Collapsed) != 0)
{
// Wait
Wait(Constants.TIMEOUT_TINY);
}
}
}
and you want to find the folder:C:\Program Files\Adobe
then the code will open the folders upto:
@"My Computer\C:\Program Files\Common Files\Adobe\Color\Profiles\Recommended"
Then it will try to open the following following folder:C:\Program Files\Common Files
Now ifyou try to use the following line of code, then the node's child count is set to zero:C:\Program Files\Adobe
Code: Select all
node = treeView.Element.FindChild(Role.OutlineItem, node.Name, node.Class, node.Location);
Code: Select all
node = treeView.Element.FindChild(Role.Outline, node.Name, node.Class, node.Location);
Does anyone have the code to locate a folder in the treeview?
Appreciate your help.
Thank you.
Behdad.