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; }

Parameters

rowIndex
Type: System.Int32
The zero-based index of the row containing the value.
columnIndex
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.

ExceptionCondition
ArgumentOutOfRangeException

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, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft