# TreeViewExtensions

Namespace: **Wisej.Web.Markup**

Assembly: **Wisej.Framework** (4.0.0.0)

Adds [fluent markup](https://learn.microsoft.com/en-us/dotnet/communitytoolkit/maui/markup/markup) extension methods to the [TreeView](/api/wisej.web/lists-and-grids/treeview.md) class.

{% tabs %}
{% tab title="C#" %}

```csharp
public class TreeViewExtensions
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class TreeViewExtensions
```

{% endtab %}
{% endtabs %}

## Methods

### ![](/files/lIX317sDtMTZJBi9oSIx) Nodes\<TTreeView>(treeView, nodes)

Adds an array of root nodes to the specified [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                 | Description                                                                                                |
| ------------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| **TTreeView** |                                                                                      | The type of the tree view, which must inherit from [TreeView](/api/wisej.web/lists-and-grids/treeview.md). |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md) | The tree view to which the root nodes will be added.                                                       |
| **nodes**     | [TreeNode\[\]](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md)        | An array of tree nodes to be added as root nodes.                                                          |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The tree view with the updated root nodes.

This method allows you to add multiple root nodes to a tree view control.

```csharp

myTreeView.Nodes(new TreeNode("Root1"), new TreeNode("Root2"));

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnAfterCheck\<TTreeView>(treeView, action)

Extension method to attach an action to the AfterCheck event of a TreeView.

| Parameter     | Type                                                                                           | Description                                                   |
| ------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------- |
| **TTreeView** |                                                                                                | The type of the TreeView, which must inherit from TreeView.   |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)           | The TreeView instance to attach the event handler to.         |
| **action**    | [Action\<TTreeView, TreeViewEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute when the AfterCheck event is triggered. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The original TreeView instance with the event handler attached.

This method allows you to execute a custom action whenever a node in the TreeView is checked or unchecked.

```csharp

treeView.OnAfterCheck((tv, e) => {
// Custom logic here
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnAfterCollapse\<TTreeView>(treeView, action)

Extension method to attach an action to the AfterCollapse event of a TreeView.

| Parameter     | Type                                                                                           | Description                                                      |
| ------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| **TTreeView** |                                                                                                | The type of the TreeView, which must inherit from TreeView.      |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)           | The TreeView instance to attach the event handler to.            |
| **action**    | [Action\<TTreeView, TreeViewEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute when the AfterCollapse event is triggered. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The original TreeView instance with the event handler attached.

This method allows you to execute a custom action whenever a node in the TreeView is collapsed.

```csharp

treeView.OnAfterCollapse((tv, e) => {
// Custom logic here
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnAfterExpand\<TTreeView>(treeView, action)

Attaches an action to be executed after a node is expanded in the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                           | Description                                     |
| ------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| **TTreeView** |                                                                                                | The type of the TreeView.                       |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)           | The TreeView instance to configure.             |
| **action**    | [Action\<TTreeView, TreeViewEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute after a node is expanded. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to specify an action that will be executed after a node is expanded in the TreeView.

```csharp

var treeView = new TreeView();
treeView.OnAfterExpand((tv, e) => { /* action */ });

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnAfterSelect\<TTreeView>(treeView, action)

Attaches an action to be executed after a node is selected in the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                           | Description                                     |
| ------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------------- |
| **TTreeView** |                                                                                                | The type of the TreeView.                       |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)           | The TreeView instance to configure.             |
| **action**    | [Action\<TTreeView, TreeViewEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute after a node is selected. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to specify an action that will be executed after a node is selected in the TreeView.

```csharp

var treeView = new TreeView();
treeView.OnAfterSelect((tv, e) => { /* action */ });

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnBeforeCheck\<TTreeView>(treeView, action)

Extension method to attach an action to the BeforeCheck event of a TreeView.

| Parameter     | Type                                                                                                 | Description                                                    |
| ------------- | ---------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| **TTreeView** |                                                                                                      | The type of the TreeView, which must inherit from TreeView.    |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)                 | The TreeView instance to attach the event handler to.          |
| **action**    | [Action\<TTreeView, TreeViewCancelEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute when the BeforeCheck event is triggered. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The original TreeView instance with the event handler attached.

This method allows you to execute a custom action before a node in the TreeView is checked or unchecked.

```csharp

treeView.OnBeforeCheck((tv, e) => {
// Custom logic here
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnBeforeCollapse\<TTreeView>(treeView, action)

Extension method to attach an action to the BeforeCollapse event of a TreeView.

| Parameter     | Type                                                                                                 | Description                                                       |
| ------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| **TTreeView** |                                                                                                      | The type of the TreeView, which must inherit from TreeView.       |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)                 | The TreeView instance to attach the event handler to.             |
| **action**    | [Action\<TTreeView, TreeViewCancelEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute when the BeforeCollapse event is triggered. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The original TreeView instance with the event handler attached.

This method allows you to execute a custom action before a node in the TreeView is collapsed.

```csharp

treeView.OnBeforeCollapse((tv, e) => {
// Custom logic here
});

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnBeforeExpand\<TTreeView>(treeView, action)

Attaches an action to be executed before a node is expanded in the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                                 | Description                                      |
| ------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| **TTreeView** |                                                                                                      | The type of the TreeView.                        |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)                 | The TreeView instance to configure.              |
| **action**    | [Action\<TTreeView, TreeViewCancelEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute before a node is expanded. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to specify an action that will be executed before a node is expanded in the TreeView.

```csharp

var treeView = new TreeView();
treeView.OnBeforeExpand((tv, e) => { /* action */ });

```

### ![](/files/lIX317sDtMTZJBi9oSIx) OnBeforeSelect\<TTreeView>(treeView, action)

Attaches an action to be executed before a node is selected in the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                                 | Description                                      |
| ------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
| **TTreeView** |                                                                                                      | The type of the TreeView.                        |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md)                 | The TreeView instance to configure.              |
| **action**    | [Action\<TTreeView, TreeViewCancelEventArgs>](https://docs.microsoft.com/dotnet/api/system.action-2) | The action to execute before a node is selected. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to specify an action that will be executed before a node is selected in the TreeView.

```csharp

var treeView = new TreeView();
treeView.OnBeforeSelect((tv, e) => { /* action */ });

```

### ![](/files/lIX317sDtMTZJBi9oSIx) ShowLoader\<TTreeView>(treeView, value)

Sets the loader visibility of the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                 | Description                                                    |
| ------------- | ------------------------------------------------------------------------------------ | -------------------------------------------------------------- |
| **TTreeView** |                                                                                      | The type of the TreeView.                                      |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md) | The TreeView instance to configure.                            |
| **value**     | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean value indicating whether the loader should be shown. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to show or hide a loader on a TreeView.

```csharp

var treeView = new TreeView();
treeView.ShowLoader(true);

```

### ![](/files/lIX317sDtMTZJBi9oSIx) VirtualScroll\<TTreeView>(treeView, value)

Sets the virtual scrolling capability of the [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

| Parameter     | Type                                                                                 | Description                                                             |
| ------------- | ------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
| **TTreeView** |                                                                                      | The type of the TreeView.                                               |
| **treeView**  | [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md) | The TreeView instance to configure.                                     |
| **value**     | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean)                      | A boolean value indicating whether virtual scrolling should be enabled. |

**Returns:** [TTreeView](/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md). The configured TreeView instance.

This method allows you to enable or disable virtual scrolling on a TreeView.

```csharp

var treeView = new TreeView();
treeView.VirtualScroll(true);

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web.markup/extensions/wisej.web.markup.treeviewextensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
