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

Search radtreeview nodes

13 Answers 1162 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Gerbrand
Top achievements
Rank 1
Gerbrand asked on 08 Jan 2008, 10:30 AM
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

13 Answers, 1 is accepted

Sort by
0
Gerbrand
Top achievements
Rank 1
answered on 08 Jan 2008, 10:42 AM
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?
0
Jordan
Telerik team
answered on 09 Jan 2008, 08:27 AM
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
0
Laz
Top achievements
Rank 1
answered on 23 Apr 2009, 01:57 PM
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

0
Victor
Telerik team
answered on 24 Apr 2009, 03:26 PM
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.
0
Laz
Top achievements
Rank 1
answered on 27 Apr 2009, 07:44 AM

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

 

0
Victor
Telerik team
answered on 27 Apr 2009, 09:30 AM
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.
0
Laz
Top achievements
Rank 1
answered on 27 Apr 2009, 09:56 AM
Works great, thanks for the solution
0
Neerav
Top achievements
Rank 1
answered on 21 Dec 2010, 02:54 PM
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
0
Neerav
Top achievements
Rank 1
answered on 21 Dec 2010, 03:00 PM
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


0
Julian Benkov
Telerik team
answered on 27 Dec 2010, 11:46 AM
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.
0
Stefan
Telerik team
answered on 18 Mar 2011, 08:25 AM
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
0
Nazme
Top achievements
Rank 1
answered on 14 Feb 2013, 02:16 AM
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.
0
Stefan
Telerik team
answered on 18 Feb 2013, 02:06 PM
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.
Tags
Treeview
Asked by
Gerbrand
Top achievements
Rank 1
Answers by
Gerbrand
Top achievements
Rank 1
Jordan
Telerik team
Laz
Top achievements
Rank 1
Victor
Telerik team
Neerav
Top achievements
Rank 1
Julian Benkov
Telerik team
Stefan
Telerik team
Nazme
Top achievements
Rank 1
Share this question
or