Databinding Treeview and Search

5 posts, 1 answers
  1. kris860911
    kris860911 avatar
    8 posts
    Member since:
    Jun 2007

    Posted 27 Mar 2008 Link to this post

    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
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 28 Mar 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. TECH GURU
    TECH GURU avatar
    1 posts
    Member since:
    Aug 2009

    Posted 16 Sep 2009 Link to this post

    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
  5. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 17 Sep 2009 Link to this post

    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.
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 Mar 2011 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready