# DataGridViewColumnCollection

Namespace: **Wisej.Web**

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

* [BaseCollection](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.basecollection)
  * [DataGridViewColumnCollection](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumncollection)

Represents a collection of [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) objects in a [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control.

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

```csharp
public class DataGridViewColumnCollection : BaseCollection, IList, IList<DataGridViewColumn>, ICollection<DataGridViewColumn>, IEnumerable<DataGridViewColumn>
```

{% endtab %}

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

```visual-basic
Public Class DataGridViewColumnCollection
    Inherits BaseCollection
    Implements IList, IList(Of DataGridViewColumn), ICollection(Of DataGridViewColumn), IEnumerable(Of DataGridViewColumn)
```

{% 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) DataGridViewColumnCollection(dataGrid)

Initializes a new instance of the [DataGridViewColumnCollection](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumncollection) class for the given [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview).

| Name         | Type                                                                              | Description                                                                                                         |
| ------------ | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
| **dataGrid** | [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) | The [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) that created 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) Item(index)

[DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn): Returns the column at the given index in the collection.

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)*index* is less than zero or greater than the number of columns in the collection minus one.

### ![](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(name)

[DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn): Returns the column of the given name in the collection.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*name* 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) List

[IList](https://docs.microsoft.com/dotnet/api/system.collections.ilist): Returns the collection.

## 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(column)

Adds the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) to the collection.

| Parameter  | Type                                                                                                                 | Description                                                                                                                      |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **column** | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) to add. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the column.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*column* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(name)

Adds a [DataGridViewTextBoxColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn) with the given column name to the collection.

| Parameter | Type                                                          | Description                                    |
| --------- | ------------------------------------------------------------- | ---------------------------------------------- |
| **name**  | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name by which the column will be referred. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the column.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(name, valueType)

Adds a [DataGridViewTextBoxColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn) with the given column name and call value type to the collection.

| Parameter     | Type                                                          | Description                                                                               |
| ------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| **name**      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name by which the column will be referred.                                            |
| **valueType** | [Type](https://docs.microsoft.com/dotnet/api/system.type)     | The [Type](https://docs.microsoft.com/dotnet/api/system.type) of the values in the cells. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the column.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(name, caption)

Adds a [DataGridViewTextBoxColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn) with the given column name and column header text to the collection.

| Parameter   | Type                                                          | Description                                    |
| ----------- | ------------------------------------------------------------- | ---------------------------------------------- |
| **name**    | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name by which the column will be referred. |
| **caption** | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text for the column's header.              |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the column.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(name, caption, valueType)

Adds a [DataGridViewTextBoxColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn) with the given column name, column header text, and cell value type to the collection.

| Parameter     | Type                                                          | Description                                                                               |
| ------------- | ------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| **name**      | [String](https://docs.microsoft.com/dotnet/api/system.string) | The name by which the column will be referred.                                            |
| **caption**   | [String](https://docs.microsoft.com/dotnet/api/system.string) | The text for the column's header.                                                         |
| **valueType** | [Type](https://docs.microsoft.com/dotnet/api/system.type)     | The [Type](https://docs.microsoft.com/dotnet/api/system.type) of the values in the cells. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the column.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(newColumns)

Adds a range of columns to the collection.

| Parameter      | Type                                                                                                                     | Description                                                                                                                                      |
| -------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **newColumns** | [DataGridViewColumn\[\]](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | An array of [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) objects to add. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*newColumns* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control.
* Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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()

Clears the collection.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added: - Selecting all cells in the control. - Clearing the selection.Updating column [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property values. Or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events: - [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter) - [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave) - [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating) - [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated) - [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter) - [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave) - [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated) - [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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)

Clears the collection and disposes the columns.

| Parameter   | Type                                                            | Description |
| ----------- | --------------------------------------------------------------- | ----------- |
| **dispose** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) |             |

### ![](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(column)

Determines whether the collection contains the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn).

| Parameter  | Type                                                                                                                 | Description                                                                                                                           |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| **column** | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) to look for. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the given column is in 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) Contains(name)

Determines whether the collection contains the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn).

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

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the given column is in 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) CopyTo(array, index)

Copies the items from the collection to the given array.

| Parameter | Type                                                                                                                     | Description                                                                                                                                 |
| --------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------- |
| **array** | [DataGridViewColumn\[\]](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The destination [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) array. |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                                              | The index of the destination array at which to start copying.                                                                               |

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

Returns the number of columns that match the *includeFilter* .

| Parameter         | Type                                                                                                                               | Description                                                                                                                                                                   |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The number of columns that match the filter.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*includeFilter* is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

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

Returns the width, in pixels, required to display all of the columns that meet the *includeFilter* .

| Parameter         | Type                                                                                                                               | Description                                                                                                                                                                   |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The width, in pixels, that is necessary to display all of the columns that match the filter.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*includeFilter* is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

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

Returns the first [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) in display order that matches the *includeFilter* and *excludeFilter* .

| Parameter                                                                                                                                                                                                                       | Type                                                                                                                               | Description                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |
| **excludeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for exclusion. |

**Returns:** [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn). The first [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) in display order that matches the given filters, or null if no column is found.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  At least one of the filter values is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

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

Returns the last [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) in display order that matches the *includeFilter* and *excludeFilter* .

| Parameter                                                                                                                                                                                                                       | Type                                                                                                                               | Description                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |
| **excludeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for exclusion. |

**Returns:** [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn). The last displayed [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) in display order that matches the specified filters, or null if no column is found.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  At least one of the filter values is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

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

Returns the first [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) after the given column in display order that matches the *includeFilter* and *excludeFilter* .

| Parameter                                                                                                                                                                                                                       | Type                                                                                                                               | Description                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **startColumn**                                                                                                                                                                                                                 | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn)               | The column from which to start searching for the next column.                                                                                                                 |
| **includeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |
| **excludeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for exclusion. |

**Returns:** [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn). The next [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) that matches the filters, or null if no column is found.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*startColumn* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  At least one of the filter values is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

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

Returns the last [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) prior to the given column in display order that matches the *includeFilter* and *excludeFilter* .

| Parameter                                                                                                                                                                                                                       | Type                                                                                                                               | Description                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **startColumn**                                                                                                                                                                                                                 | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn)               | The column from which to start searching for the previous column.                                                                                                             |
| **includeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for inclusion. |
| **excludeFilter** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) | A combination of the [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values for exclusion. |

**Returns:** [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn). The previous column that matches the given filters, or null if no column is found.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*startColumn* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  At least one of the filter values is not a valid combination of [DataGridViewElementStates](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates) values.

### ![](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(column)

Returns the index of the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) in the collection.

| Parameter  | Type                                                                                                                 | Description                                                                                                                                      |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **column** | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) to return the index of. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn).

### ![](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(name)

Returns the index of the [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) with the specified name from the collection.

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

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The index of the given [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*name* 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) Insert(index, column)

Inserts a [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) at the given index in the collection.

| Parameter  | Type                                                                                                                 | Description                                                                                                                         |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **index**  | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                                          | The zero-based index at which to insert the given column.                                                                           |
| **column** | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) to insert. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*column* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control
* Clearing the selection
* Updating a column's [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

or *column* already belongs to a [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control;\
or the *column* 's [SortMode](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#sortmode) property value is [Automatic](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumnsortmode#fields) and the [SelectionMode](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#selectionmode) property value is [FullColumnSelect](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewselectionmode#fields)\
or [ColumnHeaderSelect](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewselectionmode#fields). Use the control's [BeginInit](https://docs.microsoft.com/dotnet/api/system.componentmodel.isupportinitialize.begininit) and [EndInit](https://docs.microsoft.com/dotnet/api/system.componentmodel.isupportinitialize.endinit) methods to temporarily set conflicting property values;\
or the *column* 's [InheritedAutoSizeMode](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#inheritedautosizemode) property value is [ColumnHeader](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewautosizecolumnmode#fields) and the [ColumnHeadersVisible](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#columnheadersvisible) property value is false;\
or *column* has an [InheritedAutoSizeMode](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#inheritedautosizemode) property value of [Fill](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewautosizecolumnmode#fields) and a [Frozen](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#frozen) property value of true;\
or *column* has [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) and [Frozen](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#frozen) property values that would display it among a set of adjacent columns with the opposite [Frozen](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#frozen) property value;\
or the [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control contains at least one row and *column* has a [CellType](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#celltype) property value of null.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-9bf7fa01e02f4da0f9ef90d3b049ae43e664919e%2Fprotected.png?alt=media) 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.                                                                                                   |

### ![](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(column)

Removes the specified [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) from the collection.

| Parameter  | Type                                                                                                                 | Description           |
| ---------- | -------------------------------------------------------------------------------------------------------------------- | --------------------- |
| **column** | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | The column to delete. |

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*column* is not in the collection.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*column* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control
* Clearing the selection
* Updating a column's [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

### ![](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(name)

Removes the [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) with the specified name from the collection.

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

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*name* does not match the name of any column in the collection.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*name* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control
* Clearing the selection
* Updating a column's [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

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

Removes the [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) at the given index in the collection.

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

**Throws:**

* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)*index* is less than zero or greater than the number of columns in the control minus one.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) control is performing one of the following actions that temporarily prevents new columns from being added:
* Selecting all cells in the control
* Clearing the selection
* Updating a column's [DisplayIndex](https://docs.wisej.com/api/wisej.web/lists-and-grids/wisej.web.datagridviewcolumn#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview) events:
* [CellEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellenter)
* [CellLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellleave)
* [CellValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidating)
* [CellValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#cellvalidated)
* [RowEnter](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowenter)
* [RowLeave](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowleave)
* [RowValidated](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidated)
* [RowValidating](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#rowvalidating)

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

Moves the specified *column* to the new *newIndex* .

| Parameter    | Type                                                                                                                 | Description                                   |
| ------------ | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| **column**   | [DataGridViewColumn](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn) | Column to move to the new *newIndex* .        |
| **newIndex** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                                          | New index and display index of the *column* . |

This method updates both the column's index in the column collection and the display index without firing the [ColumnDisplayIndexChanged](https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/..#columndisplayindexchanged) event.

## Events

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

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