Search radtreeview nodes

14 posts, 0 answers
  1. Gerbrand
    Gerbrand avatar
    5 posts
    Member since:
    Dec 2007

    Posted 08 Jan 2008 Link to this post

    Hi,
    other question... I was trying to build a search for my treeview. But with some examples of the net for a normal treeview, I don't get it working.

    Here is my code:

    RadTreeNode[] tn = rtrvNetworkAll.Nodes[0].Nodes.Find(txtSearch.Text, true);
    for (int i = 0; i < tn.Length; i++)
    {
             rtrvNetworkAll.SelectedNode = tn[i];
             rtrvNetworkAll.Select();
             rtrvNetworkAll.Focus();
    }

    So there are nodes that can have the same name.

    I searched in the support contents of the radtreeview. Found nothing yet.

    Thanks in advanced
  2. Gerbrand
    Gerbrand avatar
    5 posts
    Member since:
    Dec 2007

    Posted 08 Jan 2008 Link to this post

    Okay I asked the question a little bit to soon I guess.
    Found a solution:

    //clear background
    RadTreeNodeCollection nodes = rtrvNetworkAll.Nodes;
    foreach (RadTreeNode n in nodes)
    {
             this.ClearRecursive(n);
    }
    //search a node with the build in find function
    foreach (RadTreeNode n in nodes)
    {
            this.FindRecursive(n);
     }

    // recursively move through the treeview nodes
    private void FindRecursive(RadTreeNode treeNode)
    {
            foreach (RadTreeNode tn in treeNode.Nodes)
            {
                    // if the text properties match, color the item
                    if (tn.Text == this.txtSearch.Text)
                    {
                        tn.BackColor = Color.Yellow;
                    }
                    FindRecursive(tn);
            }
    }

    private void ClearRecursive(RadTreeNode treeNode)
    {
           foreach (RadTreeNode tn in treeNode.Nodes)
           {
                    tn.BackColor = Color.White;
                    ClearRecursive(tn);
            }
    }

    Maybe help full for somebody else or is there a better solutions?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 09 Jan 2008 Link to this post

    Hello Gerbrand,

    Thank you for writing. The Find method compares the value of the Name property of nodes with the given search string (like the WinForms RadTreeView). As you want to use the Text property, your solution is fine.

    If you have additional questions, please contact us.

    Regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Laz
    Laz avatar
    31 posts
    Member since:
    Apr 2009

    Posted 23 Apr 2009 Link to this post

    Hi Gerbrand,
    when i use your code solution then i reach my goal.

    But  a little problem exists, can you help me?

    My Problem:
    After i have fired the "ClearRecursive" and "FindRecursive" method and select another node as the in yellow marked then the selected node is not highlighted with blue?
    Can i get solve my problem without setting the property "SelectedCssClass"?

     

    How can i restore the default settings?

    Best Regards

  6. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 24 Apr 2009 Link to this post

    Hi Laz,

    Please clarify what you mean by "...as the in yellow marked then the selected node is not highlighted with blue?"

    There is a short coming in the previous code in that it does not affect the root nodes. Here is the updated code:
     
    RadTreeNodeCollection nodes = this.radTreeView1.Nodes;  
    foreach (RadTreeNode n in nodes)  
    {  
        n.BackColor = Color.White;  
        this.ClearRecursive(n);  
    }  
    //search a node with the build in find function  
    foreach (RadTreeNode n in nodes)  
    {  
        if (n.Text == this.radTextBox1.Text)  
        {  
            n.BackColor = Color.Yellow;  
        }  
        this.FindRecursive(n);  
     
    I am looking forward to your reply.

    Greetings,
    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.
  7. Laz
    Laz avatar
    31 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Hi,

    sorry for the late reply.

    I will try to explain it by another way:

    If we expexct that we have a Parent node (named Department) and Child node (named Thomas Miller).

    I search for Thomas Miller. This Node will be marked in yellow. If now i selected the Parent node "Department", the label is not visible or not marked as selected.

    In my opinon the problem is a white label on white background.

    I hope I have explained it more understandable?

    I could even offer to send screenshots?

    Regards
    Laz

     

  8. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 27 Apr 2009 Link to this post

    Hello Laz,

    Thank you for writing. The issue is that node BackColor property is being reset to Color.White. It just has to be reset to its original color. You can do this by making a copy of the original color in the constructor of your form and when you reset the color of the nodes, you use the copy.

    Here is that in code:

    public partial class Form1 : Form  
    {  
        private Color originalNodeColor;  
        public Form1()  
        {  
            InitializeComponent();  
            originalNodeColor = this.radTreeView1.Nodes[0].BackColor;  
        }  
     
        private void radButton1_Click(object sender, EventArgs e)  
        {  
            RadTreeNodeCollection nodes = this.radTreeView1.Nodes;  
            foreach (RadTreeNode n in nodes)  
            {  
                n.BackColor = originalNodeColor;  
                this.ClearRecursive(n);  
            }  
            foreach (RadTreeNode n in nodes)  
            {  
                if (n.Text == this.radTextBox1.Text)  
                {  
                    n.BackColor = Color.Yellow;  
                }  
                this.FindRecursive(n);  
            }    
        }  
     
        private void FindRecursive(RadTreeNode treeNode)  
        {  
            foreach (RadTreeNode tn in treeNode.Nodes)  
            {  
                if (tn.Text == this.radTextBox1.Text)  
                {  
                    tn.BackColor = Color.Yellow;  
                }  
                FindRecursive(tn);  
            }  
        }  
     
        private void ClearRecursive(RadTreeNode treeNode)  
        {  
            foreach (RadTreeNode tn in treeNode.Nodes)  
            {  
                tn.BackColor = originalNodeColor;  
                ClearRecursive(tn);  
            }  
        }  

    Please write back if you have other questions.

    Regards,
    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.
  9. Laz
    Laz avatar
    31 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Works great, thanks for the solution
  10. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 21 Dec 2010 Link to this post

    Hello Telerik Staff,
    We have an issue here.

    PFA the screen shot of our current scenario.

    In "Figure1" we have a tree view "User Hierarchy". This treeview has binded with nodes using serversidecallback load on demand.
     
    Now in "Figure2" there is a "search" option on top of the page. On clicking the magnifying icon the "Search Results" grid gets opened up. Now in the grid you can see there is a "<-" arrow sign which on click will search the corresponding node in "User Hierarchy" and display the node by highlighting it in "User Hierarchy" as displayed in "Figure3" and "Figure4".
     
    "Figure4" is the actual image("Figure3" is for unserstanding purpose about the hierarchy), as it highlights the node to top of the tree("User Hierarchy").
     
    We are trying to implement the same in our demo application.
    Can you suggest us as to how to search such node in "User Hierarchy" and highlighting it in the same at the node to top of the tree("User Hierarchy").
     
    Since our tree is binded by serversidecallback load on demand, using RadTreeView.GetAllNodes() will not work if I search any child node.
    Kindly provide us proper solution to this and let us know if we are not going correct.
     
    Awaiting your reply.
     
    Thanks and Regards
  11. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 21 Dec 2010 Link to this post

    Hello Telerik Staff,
    It seemd that the forum does not allow to attach files.

    My question continues as how to find a node in telerik:radtreeview which is binded by nodes from serversidecallback.
    After finding node how can I focus it and expand the tree. Since the tree is bind through serversidecallback, using RadTreeView.GetAllNodes() will not work if I search any child node. Kindly provide us proper solution to this and let us know if we are not going correct.

    Thanks and Regards

    Neerav Patel


  12. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 27 Dec 2010 Link to this post

    Hello Neerav,

    Please find the answer to this question in your other forum post here. Please avoid posting the same questions twice, as this may slow down our response.

    Greetings,
    Julian Benkov
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  13. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 18 Mar 2011 Link to this post

    Hi Neerav,

    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 about this release, please refer to this blog post.

    All the best,
    Stefan
    the Telerik team
  14. Nazme
    Nazme avatar
    2 posts
    Member since:
    Feb 2013

    Posted 13 Feb 2013 Link to this post

    Hi,
    For my project I have to compare all the node between two treeviews. DO you have any sample code for that.
    I actually almost did it. But it is not working only for the root node. Other nodes are fine.
    Thanks.
  15. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 18 Feb 2013 Link to this post

    Hi Nazme,

    Please take a look at the following article, which demonstrates how to get a flattened list of the nodes in RadTreeView: http://www.telerik.com/community/code-library/winforms/general/get-a-flattened-list-of-all-radmenuitems-in.aspx.

    Once you get the list, you can compare the desired nodes.

    I hope this helps.

    All the best,
    Stefan
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready