SelectPath and Path Seperator in TreeView

Class library usage, coding and language questions.
Posts: 1
Joined: Mon Jan 21, 2008 1:28 pm

SelectPath and Path Seperator in TreeView

Post by Klaes » Mon Feb 18, 2008 10:41 am


The Ranorex.TreeView class uses a simple slash "/" to seperate the nodes within the SelectPath() method. In general this works fine!

But how can I use SelectPath() even if a TreeView contain nodes with slashes e.g. "n/a"? Is there a way to "escape" the slash? Well, how can I tell SelectPath() that the following slash is NO path seperator but a node text?

Thanks in advance!

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Feb 18, 2008 1:44 pm

I found a workaround in an old thread: ... w-t95.html

I tried it with the sample VS2005Application and it worked for me.
(I changed the node "SecondNode - FirstChild" to "Second/Node - FirstChild")

Can you please try the following code:

Code: Select all

TreeView treeView = form.FindTreeView("treeView1");
LocatePath(form, treeView, @"SecondNode\Second/Node - FirstChild");

static void LocatePath(Form form, TreeView treeView, string path)
    // Break down the path 
    string[] folderList = path.Split(@"\".ToCharArray());

    // Locate the path 
    bool ret = Locate(treeView, folderList);

static bool Locate(TreeView treeView, string[] folderList)
    // Get the root tree view element in the control 
    // The tree view itself has the role Role.Outline 
    Element treeElement = treeView.Element.FindChild(Role.Outline);

    // Get the count of the children 
    int childCount = treeElement.GetChildCount;
    // Traverse the tree 
    int level = 0;
    for (int i = 0; i < childCount && level < folderList.Length; i++)
        Element node = treeElement.GetChild(i);
        if (node == null)

        if (node.Name == folderList[level])
            node.Select(Selection.TakeFocus | Selection.TakeSelection);
            if (level == folderList.Length - 1)
                return true;
    return false;
Ranorex Support Team