# Add Nodes

This topic provides details about adding and removing nodes in TreeView via code.

## Content

### Adding Nodes

The [C1TreeNodeCollection](/componentone/docs/win/online-treeview/) class provides the [Add](/componentone/docs/win/online-treeview/) method and the [Insert](/componentone/docs/win/online-treeview/) method for adding nodes in TreeView. To add a parent node, you can use either of the two methods with the [Nodes](/componentone/docs/win/online-treeview/) collection of the [C1TreeView](/componentone/docs/win/online-treeview/) class. Next, to add a child node in the parent node, or children nodes in a child node, you can either use the [Add](/componentone/docs/win/online-treeview/) method or the [Insert](/componentone/docs/win/online-treeview/) method with the [Nodes](/componentone/docs/win/online-treeview/) collection of the [C1TreeNode](/componentone/docs/win/online-treeview/) class.

The following code snippet demonstrates how to add nodes in the TreeView control using the [Add](/componentone/docs/win/online-treeview/) method.

```vbnet
' create parent nodes
Dim parentNode1 As New C1.Win.TreeView.C1TreeNode()
Dim parentNode2 As New C1.Win.TreeView.C1TreeNode()
' add the parent nodes to the TreeView Nodes collection
C1TreeView1.Nodes.Add(parentNode1)
C1TreeView1.Nodes.Add(parentNode2)
' set the values of the parent nodes
parentNode1.SetValue("Parent1", 0)
parentNode2.SetValue("Parent2", 0)
' create child nodes
Dim childNode1 As New C1.Win.TreeView.C1TreeNode()
Dim childNode2 As New C1.Win.TreeView.C1TreeNode()
' add the child nodes to the parent nodes' Nodes collection
parentNode1.Nodes.Add(childNode1)
parentNode2.Nodes.Add(childNode2)
' set the values of the child nodes
childNode1.SetValue("Child1", 0)
childNode2.SetValue("Child2", 0)
```

```csharp
// create parent nodes
C1.Win.TreeView.C1TreeNode parentNode1 = new C1.Win.TreeView.C1TreeNode();
C1.Win.TreeView.C1TreeNode parentNode2 = new C1.Win.TreeView.C1TreeNode();
// add the parent nodes to the TreeView Nodes collection
c1TreeView1.Nodes.Add(parentNode1);
c1TreeView1.Nodes.Add(parentNode2);
// set the values of the parent nodes
parentNode1.SetValue("Parent1", 0);
parentNode2.SetValue("Parent2", 0);
// create child nodes
C1.Win.TreeView.C1TreeNode childNode1 = new C1.Win.TreeView.C1TreeNode();
C1.Win.TreeView.C1TreeNode childNode2 = new C1.Win.TreeView.C1TreeNode();
// add the child nodes to the parent nodes' Nodes collection
parentNode1.Nodes.Add(childNode1);
parentNode2.Nodes.Add(childNode2);
// set the values of the child nodes
childNode1.SetValue("Child1", 0);
childNode2.SetValue("Child2", 0);
```

The following image shows the treeview after adding nodes.

![TreeView with added nodes](https://cdn.mescius.io/document-site-files/images/56bb69d1-e225-4d79-8965-f70a0e789043/images/addingandremovingnodes1.png)

The following code snippet demonstrates how to add nodes in the TreeView control using the [Insert](/componentone/docs/win/online-treeview/) method.

```vbnet
' create third parent node
Dim parentNode3 As New C1.Win.TreeView.C1TreeNode()
' insert the third parent node in the TreeView Nodes collection
C1TreeView1.Nodes.Insert(2, parentNode3)
' set the value of the third parent node
parentNode3.SetValue("Parent3", 0)
' create third child node
Dim childNode3 As New C1.Win.TreeView.C1TreeNode()
' insert the third child node in the third parent node's Nodes collection
parentNode3.Nodes.Insert(0, childNode3)
' set the value of the third child node
childNode3.SetValue("Child3", 0)
```

```csharp
// create third parent node
C1.Win.TreeView.C1TreeNode parentNode3 = new C1.Win.TreeView.C1TreeNode();
// insert the third parent node in the TreeView Nodes collection
c1TreeView1.Nodes.Insert(2, parentNode3);
// set the value of the third parent node
parentNode3.SetValue("Parent3", 0);
// create third child node
C1.Win.TreeView.C1TreeNode childNode3 = new C1.Win.TreeView.C1TreeNode();
// insert the third child node in the third parent node's Nodes collection
parentNode3.Nodes.Insert(0, childNode3);
// set the value of the third child node
childNode3.SetValue("Child3", 0);
```

The final treeview appears, as shown below.

![TreeView with added nodes](https://cdn.mescius.io/document-site-files/images/56bb69d1-e225-4d79-8965-f70a0e789043/images/addingandremovingnodes2.png)