문제

i added a SampleNode to the treeview.

if i remove any node from SampleNode,

like,

TreeNode[] nodes = this.SampleNode.Nodes.Find(node.Text, true);
      if (nodes.Length > 0)
      {
        int j = nodes[0].Index;
        if (nodes.Length > 0)
          this.SampleNode.Nodes[j].Remove();
      }

it is deleted in treeview but not in SampleNode. Why does this happens?

what is the solution?

도움이 되었습니까?

해결책

Code to add some nodes.

 TreeNode root = new TreeNode("Root");

 root.Nodes.Add("1", "Sampl1");
 root.Nodes.Add("2", "Sampl2");
 root.Nodes.Add("3", "Sampl3");
 treeView1.Nodes.Add(root);

Code to search and delete a node,

TreeNode []nodes= treeView1.Nodes.Find("1", true);

 if (nodes.Length != 0)
  {
    //nodes[0].Remove();
    //or
    treeView1.Nodes.Remove(nodes[0]);
  }

다른 팁

The problem is might be that you are removing nodes by the index in the nodes array - not by their position in the tree.

Try replacing:

this.SampleNode.Nodes[j].Remove();

With:

this.SampleNode.Nodes.Remove(nodes[0]); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top