# Expand and Collapse Nodes

This topic provide info about expanding and collapsing nodes in applications using TreeView.

## Content

### Expanding Nodes

The [C1TreeNode](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeNode.html) class provides the [Expand](/componentone/api/win/online-treeview/dotnet-api/C1.Win.10/C1.Framework.TreeRow.Expanded.html) method to expand a single node (parent or child). The **Expand** method accepts Boolean values to determine whether the child nodes within a particular node should expand or not. On setting this method to true, all the child nodes along with the selected node gets expanded. If set to false, only the node at which the method is called gets expanded. The following code snippet demonstrates how to expand a single node using the Expand method.

```vbnet
' expand the first parent node without expanding its child nodes
parentNode1.Expand(False)
```

```csharp
// expand the first parent node without expanding its child nodes
parentNode1.Expand(false);
```

The parent node gets expanded without expanding the child nodes, as shown below.

![C1WinForms TreeView - Expanded parent node](https://cdn.mescius.io/document-site-files/images/56bb69d1-e225-4d79-8965-f70a0e789043/images/expandingcollapsingnodes1.png)

The **C1TreeNode** class also provides the **Expanded** property to expand a single node at a time.

Additionally, the [C1TreeView](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeView.html) class provides the [ExpandAll](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeView.ExpandAll.html) method to fully expand a TreeView. In fully expanded state, the TreeView displays all the children nodes under a parent node as shown in the image below.

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

The following code snippet demonstrates how to fully expand a TreeView using the **ExpandAl**l method.

```vbnet
' call the ExpandAll method
C1TreeView1.ExpandAll()
```

```csharp
// call the ExpandAll method
c1TreeView1.ExpandAll();
```

Once the TreeView is in fully expanded state, you can prevent it from collapsing. This can be achieved by cancelling the [Collapsing](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeView.Collapsing.html) event of the **C1TreeView** class as demonstrated in the code below.

```vbnet
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ' call the ExpandAll method
    C1TreeView1.ExpandAll()
    ' handle the Collapsing event
    AddHandler C1TreeView1.Collapsing, AddressOf C1TreeView1_Collapsing
End Sub
Private Sub C1TreeView1_Collapsing(sender As Object, e As C1TreeViewCancelEventArgs)
    ' cancel the event
    e.Cancel = True
End Sub
```

```csharp
private void Form1_Load(object sender, EventArgs e)
{
    // call the ExpandAll method
    c1TreeView1.ExpandAll();
    // handle the Collapsing event
    c1TreeView1.Collapsing += C1TreeView1_Collapsing; ;
}
private void C1TreeView1_Collapsing(object sender, C1.Win.TreeView.C1TreeViewCancelEventArgs e)
{
    // cancel the event
    e.Cancel = true;
}
```

### Collapsing Nodes

The **C1TreeView** class provides the [CollapseAll](/componentone/api/win/online-treeview/dotnet-api/C1.Win.TreeView.10/C1.Win.TreeView.C1TreeView.CollapseAll.html) method to fully collapse a TreeView. To collapse a single node (parent or child), the C1TreeNode class provides the Collapse method. This method accepts Boolean values to determine whether the child nodes within a particular node should collapse or not. On setting this method to true, all the child nodes along with the selected node gets collapsed. If set to false, only the node at which the method is called gets collapsed.