Monday, July 3, 2017

Treenode not expanding after removing node

Leave a Comment

I am trying to replace a tree node while expanding node (parent node). Replacing works fine. But the expansion not happening. Do you have any work around?

Code below:

 <asp:TreeView ID="tvContentTree" runat="server"  RootNodeStyle-CssClass="RootAllKeys"             ParentNodeStyle-CssClass="ParentAllKeys" ShowCheckBoxes="All" ImageSet="Simple" NodeIndent="10"  OnTreeNodeExpanded="Populate_Node" >                 <HoverNodeStyle Font-Underline="True" ForeColor="#DD5555" />                 <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="0px" NodeSpacing="0px" VerticalPadding="0px" />                 <ParentNodeStyle Font-Bold="False" />                 <SelectedNodeStyle Font-Underline="True" ForeColor="#DD5555" HorizontalPadding="0px" VerticalPadding="0px" />             </asp:TreeView>   public void Populate_Node(Object sender, TreeNodeEventArgs e)     {             foreach (System.Web.UI.WebControls.TreeNode tn in tvContentTree.Nodes)         {            tn.ChildNodes.RemoveAt(1);            tn.ChildNodes.AddAt(1,ParentNode);                           }     } 

if i comment the line

"tn.ChildNodes.RemoveAt(1);"

Then expansion works fine. So removeat function is causing the issue.

1 Answers

Answers 1

You should find the node by its name & then remove it.

TreeNode tn = tvContentTree.FindNode("tn1"); tn.ChildNodes.RemoveAt(1); 
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment