# Control.ControlCollection

Namespace: **Wisej.Web**

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

Represents a collection of [Control](https://docs.wisej.com/api/wisej.web/general/control) objects.

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

```csharp
public class ControlCollection : ControlCollection, IList<Control>, ICollection<Control>, IEnumerable<Control>, IWisejSynchronized
```

{% endtab %}

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

```visual-basic
Public Class ControlCollection
    Inherits ControlCollection
    Implements IList(Of Control), ICollection(Of Control), IEnumerable(Of Control), IWisejSynchronized
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) ControlCollection(owner)

Initializes a new instance of the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection) class.

| Name      | Type                                                            | Description                                                                                    |
| --------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| **owner** | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) that owns this collection. |

## Properties

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) IsDisposed

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Returns whether the owner control has already been disposed.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Item(index)

[Control](https://docs.wisej.com/api/wisej.web/general/control): Returns the [Control](https://docs.wisej.com/api/wisej.web/general/control) at the specified indexed location.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Item(key)

[Control](https://docs.wisej.com/api/wisej.web/general/control): Returns the [Control](https://docs.wisej.com/api/wisej.web/general/control) with the specified key in the collection.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Owner

[Control](https://docs.wisej.com/api/wisej.web/general/control): Returns the control that owns this [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection).

## Methods

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Add(child)

Adds the specified control to the control collection.

| Parameter | Type                                                            | Description                                                                 |
| --------- | --------------------------------------------------------------- | --------------------------------------------------------------------------- |
| **child** | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) to add. |

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddRange(controls)

Adds an array of control objects to the collection.

| Parameter    | Type                                                                | Description                                                                                                   |
| ------------ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **controls** | [Control\[\]](https://docs.wisej.com/api/wisej.web/general/control) | An array of [Control](https://docs.wisej.com/api/wisej.web/general/control) objects to add to the collection. |

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Clear()

Removes all controls from the collection.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Clear(dispose)

Removes and disposes all controls from the collection.

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

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Contains(control)

Determines whether the specified control is a member of the collection.

| Parameter   | Type                                                            | Description                                                                                      |
| ----------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **control** | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) to locate in the collection. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the [Control](https://docs.wisej.com/api/wisej.web/general/control) is a member of the collection; otherwise, false.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) ContainsKey(key)

Determines whether the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection) contains an item with the specified key.

| Parameter | Type                                                          | Description                                                                                                                             |
| --------- | ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| **key**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The key to locate in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection). |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection) contains an item with the specified key; otherwise, false.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Find(type, searchAllChildren)

Searches for controls by their type and builds an array of all the controls that match.

| Parameter             | Type                                                            | Description                                                                                                                                              |
| --------------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **type**              | [Type](https://docs.microsoft.com/dotnet/api/system.type)       | The type of the controls to locate in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection). |
| **searchAllChildren** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to search all child controls; otherwise, false.                                                                                                     |

**Returns:** [Control\[\]](https://docs.wisej.com/api/wisej.web/general/control). Array of controls that are derived from the specified *type* .

**Throws:**

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

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Find(key, searchAllChildren)

Searches for controls by their name and builds an array of all the controls that match.

| Parameter             | Type                                                            | Description                                                                                                                              |
| --------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **key**               | [String](https://docs.microsoft.com/dotnet/api/system.string)   | The key to located in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection). |
| **searchAllChildren** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to search all child controls; otherwise, false.                                                                                     |

**Returns:** [Control\[\]](https://docs.wisej.com/api/wisej.web/general/control). Array of controls with the specified name.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) The *key* parameter is null or an empty string ("").

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) GetChildIndex(child, throwException)

Retrieves the index of the specified child control within the control collection, and optionally raises an exception if the specified control is not within the control collection.

| Parameter          | Type                                                            | Description                                                                                                                                                                                                                                                                                   |
| ------------------ | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **child**          | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) to search for in the control collection.                                                                                                                                                                                  |
| **throwException** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | true to throw an exception if the [Control](https://docs.wisej.com/api/wisej.web/general/control) specified in the *child* parameter is not a control in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection); otherwise, false. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). A zero-based index value that represents the location of the specified child control within the control collection; otherwise -1 if the specified [Control](https://docs.wisej.com/api/wisej.web/general/control) is not found in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection).

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception) The *child* [Control](https://docs.wisej.com/api/wisej.web/general/control) is not in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection), and the *throwException* parameter value is true.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) GetEnumerator()

Retrieves a reference to an enumerator object that is used to iterate over a [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection).

**Returns:** [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.ienumerator). An [IEnumerator](https://docs.microsoft.com/dotnet/api/system.collections.ienumerator).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) IndexOf(control)

Retrieves the index of the specified control in the control collection.

| Parameter   | Type                                                            | Description                                                                                      |
| ----------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **control** | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) to locate in the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). A zero-based index value that represents the position of the specified [Control](https://docs.wisej.com/api/wisej.web/general/control) in the [ControlCollection](https://docs.wisej.com/api/wisej.web/general/control/wisej.web.control.controlcollection).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) IndexOfKey(key)

Retrieves the index of the first occurrence of the specified item within the collection.

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

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the first occurrence of the control with the specified name in the collection.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Remove(child)

Removes the specified control from the control collection.

| Parameter | Type                                                            | Description                                                                    |
| --------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------ |
| **child** | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The [Control](https://docs.wisej.com/api/wisej.web/general/control) to remove. |

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) RemoveByKey(key)

Removes the child control with the specified key.

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

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) SetChildIndex(child, newIndex)

Sets the index of the specified child control in the collection.

| Parameter    | Type                                                            | Description                         |
| ------------ | --------------------------------------------------------------- | ----------------------------------- |
| **child**    | [Control](https://docs.wisej.com/api/wisej.web/general/control) | The child control to search for.    |
| **newIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)     | The new index value of the control. |

## Inherited By

| Name                                                                                                                                    | Description                                                            |
| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [TableLayoutControlCollection](https://docs.wisej.com/api/wisej.web/containers/tablelayoutpanel/wisej.web.tablelayoutcontrolcollection) | Represents a collection of child controls in a table layout container. |
