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.
You should find the node by its name & then remove it.
TreeNode tn = tvContentTree.FindNode("tn1");
tn.ChildNodes.RemoveAt(1);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With