删除节点后TreeNode无法扩展 [英] Treenode not expanding after removing node
本文介绍了删除节点后TreeNode无法扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在扩展节点(父节点)时替换树节点.更换工作正常.但是扩张没有发生.你有工作吗?
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?
以下代码:
<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);
}
}
如果我评论这一行
"tn.ChildNodes.RemoveAt(1);"
"tn.ChildNodes.RemoveAt(1);"
然后扩展正常.因此removeat函数导致了此问题.
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);
这篇关于删除节点后TreeNode无法扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文