We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Moving Treenodes

Thread ID:





1187 Oct 2,2002 05:02 PM UTC Oct 3,2002 11:12 AM UTC WinForms 3
Tags: FAQ
Asked On October 2, 2002 05:02 PM UTC

Does anybody know how to move a treenode under VB.Net. It used to be easy under VB6, you just changed the parent property. I want to allow users to move nodes within a parent node i.e Parent --Child1 --Child2 --Child3 will become :- Parent --Child1 --Child3 --Child2 Any ideas gratefully appreciated :-(

Administrator [Syncfusion]
Replied On October 2, 2002 06:27 PM UTC

I believe can you just adjust the position of the child nodes in the Parent's Nodes collection. Using say Remove and Insert, for example. -Praveen

Replied On October 3, 2002 07:38 AM UTC

I've tried allsorts but the results are not reliable, you either get clones or the nodes end up appearing at the end! Do you have a code example?

Administrator [Syncfusion]
Replied On October 3, 2002 11:12 AM UTC

The Nodes collection does not have an InsertAt method, so you may just have to rebuild the collection in the order that you want things. To do so, you can save all the nodes, then clear the Nodes collection, and add the nodes back in the order that you want them. Here is some code.
private void button1_Click(object sender, System.EventArgs e)
	//move treenode 3 to treenode 1
	int targetIndex = 1;
	int sourceIndex = 3;

	TreeNode tn = treeView1.Nodes[sourceIndex];
	TreeNode[] tnc = new TreeNode[treeView1.Nodes.Count];
	int k = 0;
	foreach(TreeNode t in treeView1.Nodes)
		tnc[k++] = t;

	for(int i = 0; i < k; i++)
		if(i == targetIndex)
		if( !tn.Equals(tnc[i]))


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon