Guido Posted June 6, 2003 Posted June 6, 2003 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 Quote
*Gurus* divil Posted June 6, 2003 *Gurus* Posted June 6, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
kevinuni Posted March 5, 2010 Posted March 5, 2010 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); } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.