Export (0) Print
Expand All

DataGrid.Item Property (Int32, Int32)

Gets or sets the value of the cell at the specified the row and column.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Object this[
	int rowIndex,
	int columnIndex
] { get; set; }


Type: System.Int32

The zero-based index of the row containing the value.

Type: System.Int32

The zero-based index of the column containing the value.

Property Value

Type: System.Object
The value, typed as Object, of the cell.


While getting or setting, the rowIndex is out of range.

While getting or setting, the columnIndex is out of range.

Setting this property changes the position of the DataView to the specified row.

The following code example prints the value contained by the cell at the specified row and index.

private void PrintCellValues(DataGrid myGrid){
    int iRow;
    int iCol;
    DataTable myTable;
    // Assumes the DataGrid is bound to a DataTable.
    myTable = (DataTable) dataGrid1.DataSource;
    for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
       for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
          Console.WriteLine(myGrid[iRow, iCol]);

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft