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:
property Object^ default[
	int rowIndex,
	int columnIndex
] {
	Object^ get(int rowIndex, int columnIndex);
	void set(int rowIndex, int columnIndex, Object^ value);
}

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.

Exception Condition
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.

void PrintCellValues( DataGrid^ myGrid )
{
   int iRow;
   int iCol;
   DataTable^ myTable;

   // Assumes the DataGrid is bound to a DataTable.
   myTable = dynamic_cast<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
Available since 1.1
Return to top
Show: