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:
- Your comparer implementation is wrong, or peraphs it uses a property that depends on the sorting itself (like
Node.Index
) - 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... - Other reasons, we need more code...
精彩评论