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

[Solved] Epand all tree nodes

4 Answers 208 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kian Cha
Top achievements
Rank 1
Kian Cha asked on 23 Jan 2008, 07:01 PM
Hi,

I tried to get the tree to expand all nodes on initial page load, but couldn't get any of the supported Expand methods to work. What was missing?

Try #1 failed.
==========
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
            RadTreeView.ExpandAllNodes();  
     }

Try #2 failed
==========
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
             ExpandAllTreeNodes(RadTreeView1.Nodes);
    } 

    private void ExpandAllTreeNodes(RadTreeNodeCollection nodes)
    {
        foreach (RadTreeNode node in nodes)
        {
            node.Expanded = true;
            ExpandAllTreeNodes(node.Nodes);
        }
    }

Try #3 failed
=========
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!IsPostBack)
             ExpandAllTreeNodes(RadTreeView1.Nodes);
    }

    private void ExpandAllTreeNodes(RadTreeNodeCollection nodes)
    {
        foreach (RadTreeNode node in nodes)
        {
            node.ExpandChildNodes();
        }
    }


Thanks.

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Jan 2008, 08:41 AM
Hello Kian Cha,

Please try the following:
    RadTreeView1.ExpandAllNodes(); 

where RadTreeView1 is the ID of your RadTreeView.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Kian Cha
Top achievements
Rank 1
answered on 24 Jan 2008, 01:51 PM
Hi,

This is a copy and paste error, try #1 should say "RadTreeView1.ExpandAllNodes().

Please node that the code wouldn't have compiled if it was RadTreeView.ExpandAllNodes().

Thanks.

Kian

0
Atanas Korchev
Telerik team
answered on 24 Jan 2008, 02:12 PM
Hi Kian Cha,

I have tried the ExpandAll code in our online examples and it worked without a glitch so the problem must be elsewhere. Could you give us more details about your scenario? For example how do you populate the treeview? Do you use load on demand?

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Fero
Top achievements
Rank 1
answered on 07 Feb 2008, 02:52 AM
In case that you use XmlDataSource control to bind data into TreeView.

This won't work.

protected

void Page_Load(object sender, EventArgs e)
{

RadTreeView1.ExpandAllNodes();

}

Use this insted.

You can more advanced settings on that event

protected

void HandleNodeBound(object o, Telerik.WebControls.RadTreeNodeEventArgs e)

{

e.NodeBound.Expanded =

true;

}

Tags
TreeView
Asked by
Kian Cha
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Kian Cha
Top achievements
Rank 1
Fero
Top achievements
Rank 1
Share this question
or