This topic has not yet been rated - Rate this topic

DataGrid.Item Property

Gets or sets the value of a specified cell.

[C#] In C#, this property is the indexer for the DataGrid class.

Overload List

Gets or sets the value of a specified DataGridCell.

[Visual Basic] Overloads Public Default Property Item(DataGridCell) As Object
[C#] public object this[DataGridCell] {get; set;}
[C++] public: __property Object* get_Item(DataGridCell);
public: __property void set_Item(DataGridCell, Object*);
[JScript] DataGrid.Item (DataGridCell)

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

[Visual Basic] Overloads Public Default Property Item(Integer, Integer) As Object
[C#] public object this[int, int] {get; set;}
[C++] public: __property Object* get_Item(int, int);
public: __property void set_Item(int, int, Object*);
[JScript] DataGrid.Item (int, int)

Example

[Visual Basic, C#, C++] The following example prints the value contained by the cell at the specified row and index.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the Item property (DataGrid indexer). For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub PrintCells(ByVal myGrid As DataGrid)
    Dim iRow As Integer
    Dim iCol As Integer
    Dim myTable As DataTable
    ' Assumes the DataGrid is bound to a DataTable.
    myTable = CType(DataGrid1.DataSource, DataTable)
    For iRow = 0 To myTable.Rows.Count - 1
       For iCol = 0 To myTable.Columns.Count - 1
          Console.WriteLine(myGrid(iRow, iCol))
       Next iCol
    Next iRow
 End Sub
    

[C#] 
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]);
       }
    }
 }
    

[C++] 
private:
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->get_Item(iRow,iCol));
       }
    }
 }
    

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataGrid Class | DataGrid Members | System.Windows.Forms Namespace

Did you find this helpful?
(1500 characters remaining)