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

Treeview AutoExpand By Value

11 Answers 107 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 16 May 2011, 08:57 PM
Hi, i have a treenode that is connected to to a SQL datasource and i am adding a search capability to the tree that when a user selects the PK of that node the tree loaded will be expanded to point at that node that owns that PK.

How can this be done?

Thanks!

11 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 17 May 2011, 09:44 AM
Hello Bryan,

In order to implement this, you can follow the same logic in the following code library.
TreeNode searching.

Thanks,
Shinu.
0
Bryan
Top achievements
Rank 1
answered on 17 May 2011, 05:06 PM
@Shinu

awesome :D

0
Bryan
Top achievements
Rank 1
answered on 17 May 2011, 10:00 PM
just found out that it woulnt find a third tier Node, any solution for this?

such as Parent 1 
child1 of parent1
                                              child of child1
0
Nikolay Tsenkov
Telerik team
answered on 19 May 2011, 02:57 PM
Hi Bryan,

In order to make Shinu's "solution" to work, you can make the method recursive and remove the nested loop.


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Bryan
Top achievements
Rank 1
answered on 19 May 2011, 03:49 PM
a sample would be great to have sir!
0
Nikolay Tsenkov
Telerik team
answered on 20 May 2011, 03:58 PM
Hi Bryan,

Here you are, this should do the job:
void LoopNodes(RadTreeNodeCollection nodes)
{
    foreach (RadTreeNode node in nodes)
    {
        // process node
  
        if (node.Nodes.Count > 0)
        {
            LoopNodes(node.Nodes);
        }
    }
}


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Bryan
Top achievements
Rank 1
answered on 20 May 2011, 04:55 PM
@Nikolay

i should responded earlier but what i found out is that i have always located the node that was being searched..
the problem was expanding the parent of the multi level nodes..

using node.parent.prev does work but sometimes it doesnt..is there a better way of doing it the telerik way?

what i also did was use the get path and loaded those in an array with the ID and expanding the nodes by its id/value this is what i did such as id = pk in path (4-79-100-210) expand(4) expand(79) expand (100) etc..
0
Nikolay Tsenkov
Telerik team
answered on 20 May 2011, 06:18 PM
Hello Bryan,

I am not exactly sure I understand what seems to be the problem that you experience.
Could you, please, explain it in a bit more detail?

What I am definitely sure, is that this code, cannot span more than the second level of nodes:
//FindTreeNode function 
private void FindTreeNode(String treeNode) 
    //Looping through each node in the treeview 
    foreach (RadTreeNode node in RadTreeView1.Nodes) 
    
        //Checking the node name with the node name entered in the textbox 
        if (node.Text == treeNode) 
        
            //if the node name equal to the node name entered in the textbox setting the selected property of the node to true 
            node.Selected = true
        
        else 
        {                
            node.Selected = false
        
        //Looping through the child nodes  
        for (int i = 0; i < node.Nodes.Count; i++) 
        
           if (node.Nodes[i].Text == treeNode) 
            
                //if the node name equal to the node name entered in the textbox setting the selected property of the node to true and expanding that node. 
                node.Expanded = true
                node.Nodes[i].Selected = true
            
            else 
            
                node.Nodes[i].Selected = false
            
        
    
}


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Bryan
Top achievements
Rank 1
answered on 20 May 2011, 07:34 PM
@Nikolay

what i mean is that i thought my query was not loading every node, but it was..and find node by value and getting the path confirms this, and even expanding the whole tree and locating the node confirms this, however is there a way to expand the node by the value?and that including the parent(s) node?
0
Nikolay Tsenkov
Telerik team
answered on 23 May 2011, 08:02 AM
Hi Bryan,

You can get the node using the FindNodeByValue method of RadTreeView's.
Then you can expand its parent nodes using the ExpandParentNodes method of RadTreeNode's and expand the node itself - "node.Expand = true;".


Regards,
Nikolay Tsenkov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Bryan
Top achievements
Rank 1
answered on 23 May 2011, 03:53 PM
@Nikolay

 


this is what i needed "ExpandParentNodes"
replaced my 5 line code!

Thanks!
Tags
TreeView
Asked by
Bryan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bryan
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Share this question
or