)
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

How to copy the TreeNodeAdv and its sub nodes from WinForms TreeViewAdv to another TreeViewAdv?

Platform: WinForms |
Control: TreeViewAdv |
Published Date: August 25, 2015 |
Last Revised Date: February 4, 2020

Copy the TreeNodeadv and sub nodes

The TreeNodeAdv and its sub nodes can be copied from one TreeViewAdv to another. By using the Clone function, the TreeNodes can be copied. The copied nodes can be added to another TreeViewAdv by using the Add function in the TreeNodeAdvCollection.

To copy the selected TreeNodeAdv: You can copy the selected TreeNodeAdv to another TreeViewAdv, by using the following code example.

C#

if (this.treeViewAdv1.SelectedNode != null)
{
    // Copies the selected node.
    TreeNodeAdv copynodes = this.treeViewAdv1.SelectedNode.Clone();
    // Adds the copied selected tree node to another TreeViewAdv.
    this.treeViewAdv2.Nodes.Add(copynodes);
}

VB

If Me.treeViewAdv1.SelectedNode IsNot Nothing Then
     'Copies the selected node.
     Dim copynodes As TreeNodeAdv = Me.treeViewAdv1.SelectedNode.Clone()
      'Adds the copied selected tree node to another TreeViewAdv.
     Me.treeViewAdv2.Nodes.Add(copynodes)
End If

To copy the TreeNodeAdv based on the index:

You can copy the TreeNodeAdv based on the index, and the copied tree node can be added to another TreeViewAdv by using the following code example.

C#

//Copies the first node based on the given index.
TreeNodeAdv copynode = this.treeViewAdv1.Nodes[1].Clone();
//Adds the copied tree node to another TreeViewAdv.
this.treeViewAdv2.Nodes.Add(copynode);

VB

'Copies the first node based on the given index.
Dim copynode As TreeNodeAdv = Me.treeViewAdv1.Nodes(1).Clone()
'Adds the copied tree node to another TreeViewAdv.
Me.treeViewAdv2.Nodes.Add(copynode)

 

Before adding TreeNodeAdv to another TreeViewAdv

Figure 1: Before adding TreeNodeAdv to another TreeViewAdv

After adding TreeNodeAdv to another TreeViewAdv

Figure 2: After adding TreeNodeAdv to another TreeViewAdv

Samples:

C#: CopyTreeNode_C#

VB: CopyTreeNode_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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