开发者

Treeview insert property problem

TreeNode[] nodes = this.treeview.Nodes.Find(node.Te开发者_如何学Pythonxt, true);
      if (nodes.Length > 0)
      {
        int i = nodes[0].Index;
        if (nodes.Length > 0)
          this.treeview.Nodes.Remove(nodes[0]);
        this.treeview.Nodes.Insert(i, nodes[0]);
      }

i tried this code,

but the node nodes[0] is not inserting into the particular index.

instead it is adding at the last.

but yes i use treeviewsorter.

Any idea how to insert node without using insert

or using insert effectively with treeviewsorter??


If you have set the TreeViewNodeSorter property to a custom comparer, your TreeView nodes will automatically be sorted using that comparer.

Thus, you can't insert a node in a different position, because the position is decided using the comparer.

But, in your specific case you're removing a node and inserting it back in its original position, and you say it doesn't work when actually it should do.

This, (I'm guessing) could be due to several reasons:

  1. Your comparer implementation is wrong, or peraphs it uses a property that depends on the sorting itself (like Node.Index)
  2. The node you get with Find() (supposing is just one...), belongs to a level lower than root, but you try to remove it from root nodes and add to that level...
  3. Other reasons, we need more code...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜