# Menu.MenuItemCollection

Namespace: **Wisej.Web**

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

Represents a collection of [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) objects.

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

```csharp
public class MenuItemCollection : IList, ICollection, IEnumerable, IList<MenuItem>, ICollection<MenuItem>, IEnumerable<MenuItem>
```

{% endtab %}

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

```visual-basic
Public Class MenuItemCollection
    Inherits IList
    Implements ICollection, IEnumerable, IList(Of MenuItem), ICollection(Of MenuItem), IEnumerable(Of MenuItem)
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) MenuItemCollection(owner)

Initializes a new instance of [MenuItemCollection](/api/wisej.web/menus/wisej.web.menu.menuitemcollection.md).

| Name      | Type                                           | Description                                                                         |
| --------- | ---------------------------------------------- | ----------------------------------------------------------------------------------- |
| **owner** | [Menu](/api/wisej.web/menus/wisej.web.menu.md) | The [Menu](/api/wisej.web/menus/wisej.web.menu.md) object that owns the collection. |

## Properties

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

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Returns the number of items in the collection.

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

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Returns a value indicating whether this collection can be modified.

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

[MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md): Retrieves the item at the specified index within the collection.

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)\
  The index was less than zero; or the index was greater of equal to the count of items in the collection.

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

[MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md): Retrieves the item at the specified index within the collection.

## Methods

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

Adds an item to the list of items.

| Parameter   | Type                                                          | Description                    |
| ----------- | ------------------------------------------------------------- | ------------------------------ |
| **caption** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text of the new menu item. |

**Returns:** [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md).

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(caption, onClick)

Adds an item to the list of items.

| Parameter   | Type                                                                      | Description                           |
| ----------- | ------------------------------------------------------------------------- | ------------------------------------- |
| **caption** | [String](https://docs.microsoft.com/dotnet/api/system.string)             | The text of the new menu item.        |
| **onClick** | [EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) | An event handler for the click event. |

**Returns:** [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md).

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(caption, items)

Adds an item to the list of items.

| Parameter   | Type                                                          | Description                    |
| ----------- | ------------------------------------------------------------- | ------------------------------ |
| **caption** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text of the new menu item. |
| **items**   | [MenuItem\[\]](/api/wisej.web/menus/wisej.web.menuitem.md)    | List of child menu items.      |

**Returns:** [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md).

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

Adds an item to the list of items.

| Parameter | Type                                                   | Description        |
| --------- | ------------------------------------------------------ | ------------------ |
| **item**  | [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) | The new menu item. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32).

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(index, item)

Adds an item to the list of items.

| Parameter | Type                                                        | Description                                                                         |
| --------- | ----------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The index where to add/insert the new menu item.                                    |
| **item**  | [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md)      | The [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) to add to the collection |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32).

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

Adds a collection of items to the list.

| Parameter | Type                                                       | Description |
| --------- | ---------------------------------------------------------- | ----------- |
| **items** | [MenuItem\[\]](/api/wisej.web/menus/wisej.web.menuitem.md) |             |

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

Removes all items from the [Menu](/api/wisej.web/menus/wisej.web.menu.md).

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

Removes and disposes all items from the [Menu](/api/wisej.web/menus/wisej.web.menu.md).

| Parameter   | Type                                                            | Description                                             |
| ----------- | --------------------------------------------------------------- | ------------------------------------------------------- |
| **dispose** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Indicates whether the removed items should be disposed. |

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

Determines if the specified item is located within the collection.

| Parameter | Type                                                   | Description                                                  |
| --------- | ------------------------------------------------------ | ------------------------------------------------------------ |
| **value** | [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) | An object representing the item to locate in the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the item is located within the collection; otherwise, false.

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

Determines if the specified item is located within the collection.

| Parameter | Type                                                          | Description                    |
| --------- | ------------------------------------------------------------- | ------------------------------ |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key of the item to locate. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the item is located within the collection; otherwise, false.

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

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

| Parameter | Type                                                        | Description                                                      |
| --------- | ----------------------------------------------------------- | ---------------------------------------------------------------- |
| **dest**  | [Array](https://docs.microsoft.com/dotnet/api/system.array) | The object array to copy the collection to.                      |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The location in the destination array to copy the collection to. |

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

Finds all the items with a specific key.

| Parameter             | Type                                                            | Description                                           |
| --------------------- | --------------------------------------------------------------- | ----------------------------------------------------- |
| **key**               | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The key of the item to locate.                        |
| **searchAllChildren** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | Indicates that the search should include child items. |

**Returns:** [MenuItem\[\]](/api/wisej.web/menus/wisej.web.menuitem.md).

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

Returns an enumerator that can be used to iterate through the item collection.

**Returns:** [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.ienumerator). A [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.ienumerator) that represents the item collection.

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

Retrieves the index within the collection of the specified item.

| Parameter | Type                                                   | Description              |
| --------- | ------------------------------------------------------ | ------------------------ |
| **value** | [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) | The menu item to locate. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index where the item is located within the collection; otherwise, -1.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  The *value* parameter was null.

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

Retrieves the index within the collection of the specified item.

| Parameter | Type                                                          | Description                          |
| --------- | ------------------------------------------------------------- | ------------------------------------ |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key for the menu item to locate. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index where the item is located within the collection; otherwise, -1.

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

Removes the specified item from the list.

| Parameter | Type                                                   | Description         |
| --------- | ------------------------------------------------------ | ------------------- |
| **item**  | [MenuItem](/api/wisej.web/menus/wisej.web.menuitem.md) | The item to remove. |

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

Removes an item at the specified index.

| Parameter | Type                                                        | Description                      |
| --------- | ----------------------------------------------------------- | -------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The index of the item to remove. |

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)\
  The *index* parameter was less than zero, or the *index* parameter was greater than or equal to the count of items in the collection.

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

Removes the item with the specified key.

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


---

# 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/menus/wisej.web.menu.menuitemcollection.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.
