> For the complete documentation index, see [llms.txt](https://docs.wisej.com/api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

# TreeNodeCollection

Namespace: **Wisej.Web**

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

Represents a collection of [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects.

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

```csharp
public class TreeNodeCollection : IList, ICollection, IEnumerable, IList<TreeNode>, ICollection<TreeNode>, IEnumerable<TreeNode>
```

{% endtab %}

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

```visual-basic
Public Class TreeNodeCollection
    Inherits IList
    Implements ICollection, IEnumerable, IList(Of TreeNode), ICollection(Of TreeNode), IEnumerable(Of TreeNode)
```

{% endtab %}
{% endtabs %}

## Properties

### ![](/files/hsR4ok3152WyAf8J2C1u) Count

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Returns the total number of [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) IsReadOnly

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Returns a value indicating whether the collection is read-only.

### ![](/files/hsR4ok3152WyAf8J2C1u) Item(index)

[TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md): Returns or sets the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) at the specified index in the collection.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) being assigned is also a parent causing a circular reference.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  The value is null.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)\
  The *index* value is less than 0 or is greater than the number of tree nodes in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Item(key)

[TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md): Returns the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key from the collection.

## Methods

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(text)

Adds a new tree node with the specified label text to the end of the current [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

| Parameter | Type                                                          | Description                                                                                                |
| --------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The label text displayed by the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). A [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that represents the tree node being added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(key, text)

Creates a new [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key and text, and adds it to the collection.

| Parameter | Type                                                          | Description                                                                                           |
| --------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).            |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(key, text, imageIndex)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and image, and adds it to the collection.

| Parameter      | Type                                                          | Description                                                                                                         |
| -------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **key**        | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                          |
| **text**       | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).               |
| **imageIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(key, text, imageKey)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and image, and adds it to the collection.

| Parameter    | Type                                                          | Description                                                                                            |
| ------------ | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| **key**      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).             |
| **text**     | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).  |
| **imageKey** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(key, text, imageIndex, selectedImageIndex)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and images, and adds it to the collection.

| Parameter              | Type                                                          | Description                                                                                                         |
| ---------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **key**                | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                          |
| **text**               | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).               |
| **imageIndex**         | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **selectedImageIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to be displayed in the tree node when it is in a selected state.                             |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The tree node that was added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(key, text, imageKey, selectedImageKey)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and images, and adds it to the collection.

| Parameter            | Type                                                          | Description                                                                                                       |
| -------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| **key**              | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                        |
| **text**             | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).             |
| **imageKey**         | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **selectedImageKey** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the image to display when the node is in a selected state.                                             |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was added to the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(node)

Adds a previously created [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to the end of the [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

| Parameter | Type                                                                      | Description                                                                                             |
| --------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| **node**  | [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to add to the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index value of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) added to the [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*node* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  The *node* is currently assigned to another [TreeView](/api/wisej.web/lists-and-grids/treeview.md) or it is a parent node causing a circular reference.

### ![](/files/hsR4ok3152WyAf8J2C1u) AddRange(nodes)

Adds an array of previously created [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects to the collection.

| Parameter | Type                                                                          | Description                                                                                                                                         |
| --------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| **nodes** | [TreeNode\[\]](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | An array of [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects representing the tree nodes to add to the collection. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*nodes* is null or one of the items in the collection is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*nodes* is the child of another [TreeView](/api/wisej.web/lists-and-grids/treeview.md).

### ![](/files/hsR4ok3152WyAf8J2C1u) Clear()

Removes all tree nodes from the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Clear(dispose)

Removes and disposes all tree nodes from the collection.

| Parameter   | Type                                                            | Description                                                              |
| ----------- | --------------------------------------------------------------- | ------------------------------------------------------------------------ |
| **dispose** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Indicates whether to dispose the tree nodes removed from the collection. |

### ![](/files/hsR4ok3152WyAf8J2C1u) Contains(node)

Determines whether the specified [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) is a member of the collection.

| Parameter | Type                                                                      | Description                                                                                                |
| --------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **node**  | [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to locate in the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) is a member of the collection; otherwise, false.

### ![](/files/hsR4ok3152WyAf8J2C1u) ContainsKey(key)

Determines whether the collection contains a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key.

| Parameter | Type                                                          | Description                                                                                              |
| --------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to search for. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true to indicate the collection contains a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key; otherwise, false.

### ![](/files/hsR4ok3152WyAf8J2C1u) CopyTo(dest, index)

Copies the entire collection into an existing array at a specified location within the array.

| Parameter | Type                                                        | Description                                                 |
| --------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
| **dest**  | [Array](https://docs.microsoft.com/dotnet/api/system.array) | The destination array.                                      |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The index in the destination array at which storing begins. |

### ![](/files/hsR4ok3152WyAf8J2C1u) Find(key, searchAllChildren)

Finds the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects with specified key, optionally searching sub nodes.

| Parameter             | Type                                                            | Description                                                 |
| --------------------- | --------------------------------------------------------------- | ----------------------------------------------------------- |
| **key**               | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The name of the tree node to search for.                    |
| **searchAllChildren** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to search child nodes of tree nodes; otherwise, false. |

**Returns:** [TreeNode\[\]](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). An array of [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) objects whose [Name](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md#name) property matches the specified key.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetEnumerator()

Returns an enumerator that can be used to iterate through the [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

**Returns:** [IEnumerator\<TreeNode>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ienumerator-1). An [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.ienumerator) that represents the [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

### ![](/files/hsR4ok3152WyAf8J2C1u) IndexOf(node)

Returns the index of the specified [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) in the collection.

| Parameter | Type                                                                      | Description                                                                                                |
| --------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **node**  | [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to locate in the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the item found in the tree node collection; otherwise, -1.

### ![](/files/hsR4ok3152WyAf8J2C1u) IndexOfKey(key)

Returns the index of the first occurrence of a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key.

| Parameter | Type                                                          | Description                              |
| --------- | ------------------------------------------------------------- | ---------------------------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the tree node to search for. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of a tree node with the specified key, if found; otherwise, -1.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, node)

Inserts an existing tree node into the tree node collection at the specified location.

| Parameter | Type                                                                      | Description                                                                                                                         |
| --------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)               | The indexed location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **node**  | [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to insert into the collection.                        |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*node* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  The *node* is currently assigned to another [TreeView](/api/wisej.web/lists-and-grids/treeview.md) or it is a parent node causing a circular reference.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, text)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified text and inserts it at the specified index.

| Parameter | Type                                                          | Description                                                                                                                 |
| --------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                       |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, key, text)

Creates a tree node with the specified text and key, and inserts it into the collection.

| Parameter | Type                                                          | Description                                                                                                                 |
| --------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                  |
| **text**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                       |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, key, text, imageIndex)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and image, and inserts it into the collection at the specified index.

| Parameter      | Type                                                          | Description                                                                                                                 |
| -------------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **index**      | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **key**        | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                  |
| **text**       | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                       |
| **imageIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).         |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, key, text, imageKey)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and image, and inserts it into the collection at the specified index.

| Parameter    | Type                                                          | Description                                                                                                                 |
| ------------ | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **index**    | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). |
| **key**      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                  |
| **text**     | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                       |
| **imageKey** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).           |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, key, text, imageIndex, selectedImageIndex)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and images, and inserts it into the collection at the specified index.

| Parameter              | Type                                                          | Description                                                                                                                                        |
| ---------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| **index**              | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                        |
| **key**                | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                                         |
| **text**               | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                              |
| **imageIndex**         | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                |
| **selectedImageIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The index of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) when it is in a selected state. |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/hsR4ok3152WyAf8J2C1u) Insert(index, key, text, imageKey, selectedImageKey)

Creates a [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key, text, and images, and inserts it into the collection at the specified index.

| Parameter            | Type                                                          | Description                                                                                                                                      |
| -------------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **index**            | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)   | The location within the collection to insert the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                      |
| **key**              | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                                       |
| **text**             | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                            |
| **imageKey**         | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md).                                |
| **selectedImageKey** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the image to display in the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) when it is in a selected state. |

**Returns:** [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md). The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) that was inserted in the collection.

### ![](/files/lzopMboA31bVq8UIcbT3) OnCollectionChanged(action, element)

Fires the [CollectionChanged](#collectionchanged) event.

| Parameter   | Type                                                                                                         | Description                                                                                                                                                           |
| ----------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **action**  | [CollectionChangeAction](https://docs.microsoft.com/dotnet/api/system.componentmodel.collectionchangeaction) | One of [CollectionChangeAction](https://docs.microsoft.com/dotnet/api/system.componentmodel.collectionchangeaction) indicating the reason the collection has changed. |
| **element** | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                                | The element that was added or removed from the collection, or null.                                                                                                   |

### ![](/files/hsR4ok3152WyAf8J2C1u) Remove(node)

Removes the specified [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) from the [TreeNodeCollection](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md).

| Parameter | Type                                                                      | Description                                                                              |
| --------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| **node**  | [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) | The [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to remove. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*node* is null.

### ![](/files/hsR4ok3152WyAf8J2C1u) RemoveAt(index)

Removes a tree node from the tree node collection at a specified index.

| Parameter | Type                                                        | Description                                                                                           |
| --------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The index of the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) to remove. |

### ![](/files/hsR4ok3152WyAf8J2C1u) RemoveByKey(key)

Removes the [TreeNode](/api/wisej.web/lists-and-grids/treeview/wisej.web.treenode.md) with the specified key from the collection.

| Parameter | Type                                                          | Description                                              |
| --------- | ------------------------------------------------------------- | -------------------------------------------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name of the tree node to remove from the collection. |

## Events

### ![](/files/hsR4ok3152WyAf8J2C1u) CollectionChanged

[CollectionChangeEventHandler](https://docs.microsoft.com/dotnet/api/system.componentmodel.collectionchangeeventhandler) Fired when the collection changes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/api/wisej.web/lists-and-grids/treeview/wisej.web.treenodecollection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
