This is a migrated thread and some comments may be shown as answers.

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

3 Answers 238 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 19 Jun 2009, 09:18 AM
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

 

3 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 19 Jun 2009, 01:01 PM
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.
0
Chris
Top achievements
Rank 1
answered on 19 Jun 2009, 01:19 PM
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
0
Victor
Telerik team
answered on 19 Jun 2009, 02:57 PM
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.
Tags
Treeview
Asked by
Chris
Top achievements
Rank 1
Answers by
Victor
Telerik team
Chris
Top achievements
Rank 1
Share this question
or