# DataGridViewCellCollection

URL: https://docs.wisej.com/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection

Version: 4.1
Namespace: **Wisej.Web**

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

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

- C# - VB.NET

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

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

## Constructors

### ![Instance member](/img/api/instance.png) DataGridViewCellCollection(row)

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

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

## Properties

### ![Instance member](/img/api/instance.png) Item(column)

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) : 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 aDataGridView control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow)
- [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 sameDataGridView 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.

### ![Instance member](/img/api/instance.png) Item(index)

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) : 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 aDataGridView control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow) .
- [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.

### ![Instance member](/img/api/instance.png) Item(columnName)

[DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) : 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 aDataGridView control, or the specified cell when setting this property already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow) .

### ![Instance member](/img/api/instance.png) List

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

## Methods

### ![Instance member](/img/api/instance.png) Add(cell)

Adds a cell to the collection.

| Parameter | Type | Description | **cell** | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) | A [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) 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) already belongs to aDataGridView control, or *cell* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow) .

### ![Instance member](/img/api/instance.png) 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) | The array of [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) 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) already belongs to aDataGridView 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) , or at least two values in *cells* are references to the same [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) .

### ![Instance member](/img/api/instance.png) 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) | The array of [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) 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) already belongs to aDataGridView 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) , or at least two values in *cells* are references to the same [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) .

### ![Instance member](/img/api/instance.png) 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) already belongs to aDataGridView control.

### ![Instance member](/img/api/instance.png) 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) | A [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) to locate in the collection. 

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

### ![Instance member](/img/api/instance.png) 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) | 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. 

### ![Instance member](/img/api/instance.png) IndexOf(cell)

Returns the index of the specified cell.

| Parameter | Type | Description | **cell** | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) | 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.

### ![Instance member](/img/api/instance.png) 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) | The [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) 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) already belongs to aDataGridView control, or *cell* already belongs to a [DataGridViewRow](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewrow) .

### ![Protected member](/img/api/protected.png) OnCollectionChanged(action, element)

Fires the [CollectionChanged](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcellcollection#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. 

### ![Instance member](/img/api/instance.png) Remove(cell)

Removes the specified cell from the collection.

| Parameter | Type | Description | **cell** | [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) | The [DataGridViewCell](/api/wisej.web/lists-and-grids/datagridview/wisej.web.datagridviewcell) 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) already belongs to aDataGridView control.
- [ArgumentException](https://docs.microsoft.com/dotnet/api/system.argumentexception)*cell* could not be found in the collection.

### ![Instance member](/img/api/instance.png) 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) 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) already belongs to aDataGridView control.

## Events

### ![Instance member](/img/api/instance.png) CollectionChanged

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