# DataGridViewColumnCollection

Namespace: **Wisej.Web**

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

* [BaseCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.basecollection.md)
  * [DataGridViewColumnCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumncollection.md)

Represents a collection of [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) objects in a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) 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

### ![](/files/hsR4ok3152WyAf8J2C1u) DataGridViewColumnCollection(dataGrid)

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

| Name         | Type                                                           | Description                                                                                      |
| ------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **dataGrid** | [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) | The [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) that created this collection. |

## Properties

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

[DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md): 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.

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

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

**Throws:**

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

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

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

## Methods

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

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

| Parameter  | Type                                                                                              | Description                                                                                                   |
| ---------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| **column** | [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) | The [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Adds a [DataGridViewTextBoxColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

### ![](/files/hsR4ok3152WyAf8J2C1u) Add(name, valueType)

Adds a [DataGridViewTextBoxColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Adds a [DataGridViewTextBoxColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Adds a [DataGridViewTextBoxColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewtextboxcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Adds a range of columns to the collection.

| Parameter      | Type                                                                                                  | Description                                                                                                                   |
| -------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| **newColumns** | [DataGridViewColumn\[\]](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) | An array of [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values.\
  Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Clears the collection.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The associated [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property values. Or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events: - [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter) - [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave) - [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating) - [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated) - [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter) - [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave) - [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated) - [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Clears the collection and disposes the columns.

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

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

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

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

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

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

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

| 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.

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

Copies the items from the collection to the given array.

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

### ![](/files/hsR4ok3152WyAf8J2C1u) GetColumnCount(includeFilter)

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

| Parameter         | Type                                                                                                            | Description                                                                                                                                                |
| ----------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetColumnsWidth(includeFilter)

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

| Parameter         | Type                                                                                                            | Description                                                                                                                                                |
| ----------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetFirstColumn(includeFilter, excludeFilter)

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

| Parameter                                          | Type                                                                                                            | Description                                                                                                                                                |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for inclusion. |
| **excludeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for exclusion. |

**Returns:** [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md). The first [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetLastColumn(includeFilter, excludeFilter)

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

| Parameter                                          | Type                                                                                                            | Description                                                                                                                                                |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **includeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for inclusion. |
| **excludeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for exclusion. |

**Returns:** [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md). The last displayed [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetNextColumn(startColumn, includeFilter, excludeFilter)

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

| Parameter                                          | Type                                                                                                            | Description                                                                                                                                                |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **startColumn**                                    | [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md)               | The column from which to start searching for the next column.                                                                                              |
| **includeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for inclusion. |
| **excludeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for exclusion. |

**Returns:** [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md). The next [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetPreviousColumn(startColumn, includeFilter, excludeFilter)

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

| Parameter                                          | Type                                                                                                            | Description                                                                                                                                                |
| -------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **startColumn**                                    | [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md)               | The column from which to start searching for the previous column.                                                                                          |
| **includeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for inclusion. |
| **excludeFilter** ![](/files/1vGqtbG2j637vQ4ROWOf) | [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) | A combination of the [DataGridViewElementStates](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values for exclusion. |

**Returns:** [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md). 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewelementstates.md) values.

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

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

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

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

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

Returns the index of the [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md).

**Throws:**

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

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

Inserts a [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) | The [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

or *column* already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control;\
or the *column* 's [SortMode](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#sortmode) property value is [Automatic](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumnsortmode.md#fields) and the [SelectionMode](/api/wisej.web/lists-and-grids/datagridview.md#selectionmode) property value is [FullColumnSelect](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewselectionmode.md#fields)\
or [ColumnHeaderSelect](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewselectionmode.md#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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#inheritedautosizemode) property value is [ColumnHeader](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewautosizecolumnmode.md#fields) and the [ColumnHeadersVisible](/api/wisej.web/lists-and-grids/datagridview.md#columnheadersvisible) property value is false;\
or *column* has an [InheritedAutoSizeMode](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#inheritedautosizemode) property value of [Fill](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewautosizecolumnmode.md#fields) and a [Frozen](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#frozen) property value of true;\
or *column* has [DisplayIndex](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) and [Frozen](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#frozen) property values that would display it among a set of adjacent columns with the opposite [Frozen](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#frozen) property value;\
or the [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control contains at least one row and *column* has a [CellType](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#celltype) property value of null.

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

Fires the [CollectionChanged](#collectionchanged) event.

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

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

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

| Parameter  | Type                                                                                              | Description           |
| ---------- | ------------------------------------------------------------------------------------------------- | --------------------- |
| **column** | [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) | 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Removes the [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

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

Removes the [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) 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](/api/wisej.web/lists-and-grids/datagridview.md) 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](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md#displayindex) property value\
  or this method is being called from a handler for one of the following [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) events:
* [CellEnter](/api/wisej.web/lists-and-grids/datagridview.md#cellenter)
* [CellLeave](/api/wisej.web/lists-and-grids/datagridview.md#cellleave)
* [CellValidating](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidating)
* [CellValidated](/api/wisej.web/lists-and-grids/datagridview.md#cellvalidated)
* [RowEnter](/api/wisej.web/lists-and-grids/datagridview.md#rowenter)
* [RowLeave](/api/wisej.web/lists-and-grids/datagridview.md#rowleave)
* [RowValidated](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidated)
* [RowValidating](/api/wisej.web/lists-and-grids/datagridview.md#rowvalidating)

### ![](/files/hsR4ok3152WyAf8J2C1u) SetColumnIndex(column, newIndex)

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

| Parameter    | Type                                                                                              | Description                                   |
| ------------ | ------------------------------------------------------------------------------------------------- | --------------------------------------------- |
| **column**   | [DataGridViewColumn](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcolumn.md) | 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](/api/wisej.web/lists-and-grids/datagridview.md#columndisplayindexchanged) event.

## Events

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

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


---

# 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/lists-and-grids/datagridview/wisej.web.datagridviewcolumncollection.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.
