How can I move a node in a Treeview?

Guido

Newcomer
Joined
Jun 6, 2003
Messages
1
Hi,

Here is my problem:

How can I move a node in a treeview.

for example

Root
--1
----11
----12
----13
----14
--2
etc...

Now I would like to select 14 and move it one up so the result would be:

Root
--1
----11
----12
----14
----13
--2
etc...


If you know the answer to my problem, please help me?
Code examples would be very helpful

thanx
 
You can remove a node then use the Insert method of its parent Nodes collection to specify the index for it to be inserted at, in the children.
 
You can use something like this.

I hope this can help you. :)


TreeNodeMenu tnmNode = tvwMenuitemSup.SelectedNode;
TreeNode tnmPreviousNode =tnmNode.PrevNode;

if (tnmPreviousNode != null)
{
int idxBegin = tnmNode.Index;​
int idxEnd = tnmPreviousNode.Index;​
TreeNode tnmNodeParent = tnmNode.Parent;​
if (tnmNodeParent != null)​
{​
tnmNode.Remove();​
tnmPreviousNode.Remove();​
tnmNodeParent.Nodes.Insert(idxBegin, tnmPreviousNode);
tnmNodeParent.Nodes.Insert(idxEnd, tnmNode);​
}​
}
 
Back
Top