DataGridView.Item[] Property

Definition

Provides an indexer to get or set the cell located at the intersection of the specified row and column.

Overloads

Item[Int32, Int32]

Provides an indexer to get or set the cell located at the intersection of the column and row with the specified indexes.

Item[String, Int32]

Provides an indexer to get or set the cell located at the intersection of the row with the specified index and the column with the specified name.

Item[Int32, Int32]

Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs

Provides an indexer to get or set the cell located at the intersection of the column and row with the specified indexes.

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[int columnIndex, int rowIndex] { get; set; }

Parameters

columnIndex
Int32

The index of the column containing the cell.

rowIndex
Int32

The index of the row containing the cell.

Property Value

The DataGridViewCell at the specified location.

Attributes

Exceptions

columnIndex is less than 0 or greater than the number of columns in the control minus 1.

-or-

rowIndex is less than 0 or greater than the number of rows in the control minus 1.

Examples

The following code example demonstrates the use of this indexer.

C#
// Retrieve the cell value for the cell at column 3, row 7.
String testValue1 = (String)dataGridView1[3, 7].Value;

// Retrieve the cell value for the cell in the Name column at row 4.
String testValue2 = (String)dataGridView1["Name", 4].Value;

Remarks

This indexer is an alternative to accessing cells through the Cells collection of the Rows collection.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Item[String, Int32]

Source:
DataGridView.cs
Source:
DataGridView.cs
Source:
DataGridView.cs

Provides an indexer to get or set the cell located at the intersection of the row with the specified index and the column with the specified name.

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[string columnName, int rowIndex] { get; set; }

Parameters

columnName
String

The name of the column containing the cell.

rowIndex
Int32

The index of the row containing the cell.

Property Value

The DataGridViewCell at the specified location.

Attributes

Examples

The following code example demonstrates the use of this indexer.

C#
// Retrieve the cell value for the cell at column 3, row 7.
String testValue1 = (String)dataGridView1[3, 7].Value;

// Retrieve the cell value for the cell in the Name column at row 4.
String testValue2 = (String)dataGridView1["Name", 4].Value;

Remarks

This indexer is an alternative to accessing cells through the Cells collection of the Rows collection.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9