TreeView and node duplication question

L

lallous

Hello

I'm new to C# language and wonder if the code is correct syntax wise but not
necessarily logic wise.

private void nodeMoveUp(TreeView tv)
{
TreeNode tn = tv.SelectedNode;
if (tn == null || tn.Index == 0)
return;

int newindex = tn.Index - 1;

TreeNode newnode = (TreeNode) tn.Clone();

if (tn.Parent != null)
tn.Parent.Nodes.Insert(newindex, newnode);
else
tv.Nodes.Insert(newindex, newnode);

tn.Remove();

tv.SelectedNode = newnode;
}

Is the usage of .Clonse() to duplicate a node and then insert it into the
treeview correct?

My aim is to move a selected node directly to the position above it, while
the node above it will go down and take its place.

Regards,
Elias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top