Moving Treenodes

  • Thread starter Thread starter Bart Steur
  • Start date Start date
B

Bart Steur

Hi,

I would like to know what is the best way to move a node within a
tree/treenodecollection (not using Drag/Drop). It can't be done by changing
the index. Found some examples with remove/insert, but is that the only way?

Thanks,
Bart
 
First get and store an instance of the node you want to move...

' take from index 5
Dim myNode2 As Windows.Forms.TreeNode = TreeView1.Nodes(5) 'or can
be by key


The remove and re-insert into the tree

TreeView1.Nodes.Remove(myNode2)

' insert back into index 2
TreeView1.Nodes.Insert(2, myNode2)


You cannot edit the index structure directly, so yes, AFAIK, this is the
only way.

Cheers.
Dan
 
Back
Top