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

Databinding Treeview and Search

4 Answers 170 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
kris860911
Top achievements
Rank 1
kris860911 asked on 27 Mar 2008, 09:53 AM
Hi,
I am binding a treeview to a datatable.
The treeview has self-referencing data. And it loads correctly and shows correctly.

The problem I am having is this. Once the data is reloaded, I want to select the node that was selected already. So I need to use the Find method and make the node selected,

However, I read that the Find Method uses the Name Property to match the search term, but it seems like the Name Property is not populated when bound to a datasource.

Do you suggest a way to overcome this problem?

Thanks,
Kris

4 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 28 Mar 2008, 02:19 PM
Hi kris860911,

You can search by two different RadTreeView properties when you bind to a DataSource. The first one is the Text property, which is popluated as a DisplayMember and the second one is the Tag property which is populated as a ValueMember.

Currently, RadTreeView does not implement the FindNodeByText method, so please refer to the implementation below:

RadTreeNode FindNodeByText(RadTreeNodeCollection nodeCollection, string text)  
{  
     foreach (RadTreeNode node in nodeCollection)  
     {  
         if ((node.Text == text) && (node != this.radTreeView1.SelectedNode))  
         {  
             return node;  
         }  
         RadTreeNode result = this.FindNodeByText(node.Nodes, text);  
         if (result != null)  
         {  
             return result;  
         }  
     }  
     return null;  

I hope this helps. If you have additional questions, do not hesitate to contact me.

Best wishes,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
TECH GURU
Top achievements
Rank 1
answered on 16 Sep 2009, 10:16 PM
I found this after I posted my query. I have a question regarding the databinding implementation. Any reason why the ValueMember was copied to the Node.Tag property instead of the Node.Name property? Doing this would have eliminated the need to write a custom find method and use the Nodes.Find() method instead.

- TG
0
Victor
Telerik team
answered on 17 Sep 2009, 08:56 AM
Hi TECH GURU,

Please refer to your first ticket about the same.

Regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Stefan
Telerik team
answered on 23 Mar 2011, 04:10 PM
Hi TECH GURU,

Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.

Best wishes,
Stefan
the Telerik team
Tags
Treeview
Asked by
kris860911
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
TECH GURU
Top achievements
Rank 1
Victor
Telerik team
Stefan
Telerik team
Share this question
or