Changing the Selected Tree Node Programatically after changing Pages without using the Tree View

4 posts, 0 answers
  1. Chris
    Chris avatar
    2 posts
    Member since:
    Nov 2008

    Posted 19 Jun 2009 Link to this post

    Hi,

    Can anyone help with what seemed to be relatively easy action, and has now plagued me for sometime.

    What i require to do is change the selected "highlighted node" in my tree view when i change my current page without clicking the tree view itself.? I change page programmatically and require the tree view to correspond to the new page once it has loaded.

    I have managed to get the tree view selecting the top parent node using the following code, however and attempts to achieve anything slightly more accurate i fall short.!

    Sample Line Of Code Below.

    ((

    CS_MainForm)this.Owner).treeView.SelectedNode = ((CS_MainForm)this.Owner).treeView.Nodes[0];

    Sample Line Of Code Above.

    I have tried to change the selected node using the line of code below, but have had no joy..

    Sample Line Of Code Below.

     

    ((

    CS_MainForm)this.Owner).treeView.SelectedNode = ((CS_MainForm)this.Owner).treeView.Nodes["New Page Name"];

    Sample Line Of Code Above.

    So far all of my attempts have failed and i would be grateful if somebody could offer me some assistance. I have a feeling its staring me right in the face and i just can't see it.

    Kind Regards
    Chris

     

  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 Jun 2009 Link to this post

    Hello Chris,

    Thank you for writing.
     
    The indexer of RadTreeNodeCollection searches the nodes' Text property. If you want to search by Name or by Tag you will have to implement a recursive method. Setting the SelectedNode is the way to highlight a node, you are on the right track but you have to mind the quirk I mentioned above.
     
    Write again if you need further assistance.

    Best wishes,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    2 posts
    Member since:
    Nov 2008

    Posted 19 Jun 2009 Link to this post

    Hi Victor,

    Do you have an example..?

    Am i on the right line in thinking i have to step through the tree recursively until i find a text match, then set this node a selected..??

    Thankyou for your Prompt reply...

    Regards
    Chris
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 19 Jun 2009 Link to this post

    Hi Chris,

    Here is an example:
     
    RadTreeNode FindNode(RadTreeNodeCollection nodes, string text)  
    {  
        foreach (RadTreeNode n in nodes)  
        {  
            if (n.Text == text)  
            {  
                return n;  
            }  
        }  
     
        foreach (RadTreeNode n in nodes)  
        {  
            RadTreeNode foundNode = FindNode(n.Nodes, text);  
            if (foundNode != null)  
            {  
                return foundNode;  
            }  
        }  
     
        return null;  
    Write again if you need further assistance.

    All the best,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top