Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • 6 years later...
Posted

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);

}

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...