Ranorex

SelectPath and Path Seperator in TreeView

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet
View previous topic :: View next topic  
Author Message
Klaes



Joined: 21 Jan 2008
Posts: 1

PostPosted: Mon Feb 18, 2008 11:41 am    Post subject: SelectPath and Path Seperator in TreeView
Hello!

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!
Stephan
Back to top
View user's profile Send private message
Support Team
Site Admin


Joined: 07 Jul 2006
Posts: 257

PostPosted: Mon Feb 18, 2008 2:44 pm    Post subject:
I found a workaround in an old thread:

http://www.ranorex.com/forum/locating-a-folder-in-treeview-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: click into code to enlarge
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)
            break;

        if (node.Name == folderList[level])
        {
            node.Select(Selection.TakeFocus | Selection.TakeSelection);
            Mouse.MoveToElement(node);
            treeView.SendKeys("{RIGHT}");
            if (level == folderList.Length - 1)
                return true;
            else
                level++;
        }
    }
    return false;
}


Jenö
Ranorex Support Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum