Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treenode not expanding after removing node

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.

like image 372
SmartestVEGA Avatar asked Jun 20 '17 10:06

SmartestVEGA


1 Answers

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

TreeNode tn = tvContentTree.FindNode("tn1");
tn.ChildNodes.RemoveAt(1);
like image 74
Manoj Avatar answered Oct 25 '22 01:10

Manoj