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]

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

public:
 property System::Windows::Forms::DataGridViewCell ^ default[int, int] { System::Windows::Forms::DataGridViewCell ^ get(int columnIndex, int rowIndex); void set(int columnIndex, int rowIndex, System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[int columnIndex, int rowIndex] { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Item(int * int) : System.Windows.Forms.DataGridViewCell with get, set
Default Public Property Item(columnIndex As Integer, rowIndex As Integer) As DataGridViewCell

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.

// 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;
' Retrieve the cell value for the cell at column 3, row 7.
Dim testValue1 As String = CStr(dataGridView1(3, 7).Value)

' Retrieve the cell value for the cell in the Name column at row 4.
Dim testValue2 As String = CStr(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

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.

public:
 property System::Windows::Forms::DataGridViewCell ^ default[System::String ^, int] { System::Windows::Forms::DataGridViewCell ^ get(System::String ^ columnName, int rowIndex); void set(System::String ^ columnName, int rowIndex, System::Windows::Forms::DataGridViewCell ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCell this[string columnName, int rowIndex] { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Item(string * int) : System.Windows.Forms.DataGridViewCell with get, set
Default Public Property Item(columnName As String, rowIndex As Integer) As DataGridViewCell

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.

// 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;
' Retrieve the cell value for the cell at column 3, row 7.
Dim testValue1 As String = CStr(dataGridView1(3, 7).Value)

' Retrieve the cell value for the cell in the Name column at row 4.
Dim testValue2 As String = CStr(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