c# - Treeview: custom order after adding new root nodes -


i have 10 different root nodes don't want add untill need them (they doesn't exist, long won't call them). used

treeview1.nodes.insert(0, node); treeview1.nodes.insert(1, node); treeview1.nodes.insert(2, node); 

and on. if i'll add node0, node1 , node2 works fine. if i'll try change order node2, node1, node0, experience problem - node0 works fine, there's no node1, 2 node2 or node1 , node2 switch places. possible skip position, use in future? check node index used code, attached button:

messagebox.show(treeview1.selectednode.index.tostring()); 

i think using wrong method add nodes.

for initial creation can use treeview1.nodes.add(node). when want insert node @ given index, work out want , use insert @ appropriate index.

the reason nodes swapping places because in example above insert meaningless. inserting node in position 2 in list no nodes add @ position 0 instead.

edit: adding code sample.

        treenode node1 = new treenode("node 1");          view.nodes.add(new treenode("node 0"));         view.nodes.add(new treenode("node 2"));         view.nodes.add(new treenode("node 4"));          // point 1          view.nodes.insert(1, node1);          // point 2          view.nodes.insert(3, new treenode("node 3"));          // point 3 

at point 1 collection of nodes be
node 0
node 2
node 4

at point 2 collection of nodes be
node 0
node 1
node 2
node 4

at point 3 collection of nodes be
node 0
node 1
node 2
node 3
node 4


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -