日期:2014-05-19  浏览次数:20767 次

删除treeview子节点的奇怪问题?
TreeView.Nodes.Remove(TreeView.SelectedNode);   为什么只能删除根节点,而不能删除其下的子节点,web端控件,哪里有问题啊?谢谢


------解决方案--------------------
我在vb中是这么用的
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim parentNode As TreeNode = TreeView1.SelectedNode.Parent
parentNode.Nodes.Remove(TreeView1.SelectedNode)
End Sub
------解决方案--------------------
//写了一段代码,参考一下.
TreeView tv = new TreeView();//root
TreeNode tn = new TreeNode();//first
TreeNode tn1 = new TreeNode();//second

tn.Name = "aa ";
tn.Text = "aa.text ";
tv.Nodes .Add(tn);

tn1.Name = "aa1 ";
tn1.Text = "aa1.text ";
tn.Nodes.Add(tn1);

MessageBox.Show(tv.Nodes[ "aa "].Text);
MessageBox.Show(tv.Nodes[ "aa "].Nodes[ "aa1 "].Text);