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

Expand all nodes?

5 Answers 493 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
KevinMc
Top achievements
Rank 1
KevinMc asked on 11 Jul 2008, 02:08 PM
Is there anyway to set the default state of a treeview to expanded when it is loaded?

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 11 Jul 2008, 02:20 PM
Hi KevinMc,

You can call the ExpandAllNodes() server-side method of the treeview:

RadTreeView1.ExpandAllNodes(); 


Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
KevinMc
Top achievements
Rank 1
answered on 11 Jul 2008, 02:29 PM

It is a treeview in a combobox. If i put this in the page_load method i get null reference exception probably because it is not bound to the datasource yet.

RadTreeView cats = (RadTreeView)comboCategories.FindControl("treeCategories");  
cats.ExpandAllNodes();  
 

Where should i set the expandallnodes at in this scenario?

0
Veselin Vasilev
Telerik team
answered on 11 Jul 2008, 02:52 PM
Hello KevinMc,

You need to use this code:

RadTreeView cats = (RadTreeView)comboCategories.Items[0].FindControl("treeCategories");     
cats.ExpandAllNodes();   
 

Now it should find the treeview properly.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
KevinMc
Top achievements
Rank 1
answered on 11 Jul 2008, 02:57 PM
Adding items on findcontrol corrects the null reference exception but the treeview still is not expanded.
0
Accepted
Veselin Vasilev
Telerik team
answered on 11 Jul 2008, 03:16 PM
Hi KevinMc,

Here is another idea: subscribe to the OnClientDropDownOpening event of the combobox, find the treeview, loop thought its nodes and expand them:

function OnClientDropDownOpeningHandler(sender, eventArgs) 
    var tree = $find('<%= RadComboBox1.Items[0].FindControl("RadTreeView1").ClientID %>'); 
     
    var nodes = tree.get_allNodes(); 
        
   for (var i = 0; i < nodes.length; i++) 
   { 
       if (nodes[i].get_nodes() != null
       { 
           nodes[i].expand(); 
       } 
   } 


Kind regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
KevinMc
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
KevinMc
Top achievements
Rank 1
Share this question
or