# DataGridViewCellCollection

Namespace: **Wisej.Web**

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

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

Represents a collection of cells in a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md).

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

```csharp
public class DataGridViewCellCollection : BaseCollection, IList, IList<DataGridViewCell>, ICollection<DataGridViewCell>, IEnumerable<DataGridViewCell>
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) DataGridViewCellCollection(row)

Initializes a new instance of the [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) class.

| Name    | Type                                                                                        | Description                                                                                                               |
| ------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **row** | [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md) | The [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md) that owns the collection. |

## Properties

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

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md): Returns or sets the cell contained in the specified *column* .

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  The specified value when setting this property is null; or *column* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The specified cell when setting this property already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md)
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*column* is null.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)\
  The specified *column* does not belong to the same [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) that owns the cells.
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)\
  The index of the specified *column* is less than 0 or is equal to or greater than the number of cells in the collection.

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

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md): Returns or sets the cell at the provided index location.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  The specified value when setting this property is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The specified cell when setting this property already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md).
* [ArgumentOutOfRangeException](https://docs.microsoft.com/dotnet/api/system.argumentoutofrangeexception)*index* is less than 0 or *index* is equal to or greater than the number of cells in the collection.

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

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md): Returns or sets the cell in the column with the provided name.

**Throws:**

* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*columnName* does not match the name of any columns in the control.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)\
  The specified value when setting this property is null; or *columnName* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The specified cell when setting this property already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md).

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

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

## Methods

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

Adds a cell to the collection.

| Parameter | Type                                                                                          | Description                                                                                                               |
| --------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **cell**  | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | A [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) to add to the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The position in which to insert the new element.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or *cell* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md).

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

Adds an array of cells to the collection.

| Parameter | Type                                                                                              | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **cells** | [DataGridViewCell\[\]](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | The array of [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) objects to add to the collection. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*cells* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or at least one value in *cells* is null, or at least one cell in *cells* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md), or at least two values in *cells* are references to the same [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md).

### ![](/files/hsR4ok3152WyAf8J2C1u) AddRangeInternal(cells)

Adds an array of cells to the collection.

| Parameter | Type                                                                                              | Description                                                                                                                                  |
| --------- | ------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| **cells** | [DataGridViewCell\[\]](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | The array of [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) objects to add to the collection. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception)*cells* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or at least one value in *cells* is null, or at least one cell in *cells* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md), or at least two values in *cells* are references to the same [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md).

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

Clears all cells from the collection.

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control.

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

Determines whether the specified cell is contained in the collection.

| Parameter | Type                                                                                          | Description                                                                                                                  |
| --------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| **cell**  | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | A [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) to locate in the collection. |

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

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

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

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

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

Returns the index of the specified cell.

| Parameter | Type                                                                                          | Description                           |
| --------- | --------------------------------------------------------------------------------------------- | ------------------------------------- |
| **cell**  | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | The cell to locate in the collection. |

**Returns:** [Int32](https://docs.microsoft.com/dotnet/api/system.int32). The zero-based index of the value of *cell* parameter, if it is found in the collection; otherwise, -1.

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

Inserts a cell into the collection at the specified index.

| Parameter | Type                                                                                          | Description                                                                                                  |
| --------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32)                                   | The zero-based index at which to place *cell* .                                                              |
| **cell**  | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | The [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) to insert. |

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control, or *cell* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow.md).

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

Removes the specified cell from the collection.

| Parameter | Type                                                                                          | Description                                                                                                                      |
| --------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| **cell**  | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) | The [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) to remove from the collection. |

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control.
* [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*cell* could not be found in the collection.

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

Removes the cell at the specified index.

| Parameter | Type                                                        | Description                                                                                                                              |
| --------- | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **index** | [Int32](https://docs.microsoft.com/dotnet/api/system.int32) | The zero-based index of the [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell.md) to be removed. |

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception)\
  The row that owns this [DataGridViewCellCollection](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection.md) already belongs to a [DataGridView](/api/wisej.web/lists-and-grids/datagridview.md) control.

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