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

Expand All nodes

1 Answer 129 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
barney
Top achievements
Rank 1
barney asked on 08 Aug 2011, 05:37 AM
Hi,
I am currently wanting to implement the RadTreeView "Expand All" functionality.
I used "ServerSideCallBack" mode to expand nodes and used a menuitem to call the event(Expand All).
But when I click "ExpandAll" button to expand  a selected node which its child child nodes count is more than 5, the first time it will get correct result.
At the second time to click  "ExpandAll" button to  expand this node,  its child child nodes will appear in a confuse way. Only the top 5 child child nodes are correct, the others are wrong. Although we do nothing  but only toggle the selected node in server side codes. 

Below codes maybe helpful to understand it. Please tell me how to resolve it.

[Function:ExpandNode]
  .....
  foreach (RadTreeNode radTreeNode in treeNodes)
    {
             radTreeNode.NodeTemplate = new MyTemplate(radTreeNode);
             currentNode.Nodes.Add(radTreeNode);
             radTreeNode.DataBind();
    }
[Function:Expand All]
   if (!radTreeNode.Expanded)
      {
             if (radTreeNode.ExpandMode == TreeNodeExpandMode.ServerSideCallBack)
             {
                 ExpandNode(radTreeNode);
             }
             else if(radTreeNode.Nodes.Count>0)
             {
                  radTreeNode.Toggle();
             }
       }
       foreach (RadTreeNode node in radTreeNode.Nodes)
       {
            ExpandAllNode(node);
       }

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 11 Aug 2011, 08:40 AM
Hello Barney,

You can try this code where "RadTreeView1" is the ID of my tree:
protected void RadButton1_Click(object sender, EventArgs e)
   {
       ExpandAll(RadTreeView1.Nodes);
        
   }
 
   private void ExpandAll(RadTreeNodeCollection radTreeNodeCollection)
   {
       foreach (RadTreeNode node in radTreeNodeCollection)
       {
 
           node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
           node.Expanded = true;
 
           if (node.Nodes.Count>0)
           {
               ExpandAll(node.Nodes);
           }
 
       }
   }

This code worked at my side.

Kind regards,
Plamen Zdravkov
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.

Tags
TreeView
Asked by
barney
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or