Export (0) Print
Expand All

DataGridCell Structure

Identifies a cell in the grid.

For a list of all members of this type, see DataGridCell Members.

System.Object
   System.ValueType
      System.Windows.Forms.DataGridCell

[Visual Basic]
Public Structure DataGridCell
[C#]
public struct DataGridCell
[C++]
public __value struct DataGridCell

[JScript] In JScript, you can use the structures in the .NET Framework, but you cannot define your own.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The DataGridCell can be used in conjunction with the System.Windows.Forms.DataGrid control's CurrentCell property to get or set the value of any cell. Setting the System.Windows.Forms.DataGrid control's CurrentCell property to a DataGridCell causes the focus to move to the cell specified by the DataGridCell.

Example

[Visual Basic, C#, C++] The following example assigns the DataGridCell to the CurrentCell of a System.Windows.Forms.DataGrid and returns the column and row number of the selected cell. The value stored in the DataTable is also printed using the DataGridCell object's RowNumber and ColumnNumber.

[Visual Basic] 
Private Sub PrintCellRowAndCol()
    Dim myCell As DataGridCell
    myCell = DataGrid1.CurrentCell
    Console.WriteLine(myCell.RowNumber)
    Console.WriteLine(myCell.ColumnNumber)
    ' Prints the value of the cell through the DataTable.
    Dim myTable As DataTable
    ' Assumes the DataGrid is bound to a DataTable.
    myTable = CType(DataGrid1.DataSource, DataTable)
    Console.WriteLine(myTable.Rows(myCell.RowNumber)(myCell.ColumnNumber))
 End Sub


[C#] 
private void PrintCellRowAndCol()
{
   DataGridCell myCell;
   myCell = DataGrid1.CurrentCell;
   Console.WriteLine(myCell.RowNumber);
   Console.WriteLine(myCell.ColumnNumber);
   // Prints the value of the cell through the DataTable.
   DataTable myTable;
   // Assumes the DataGrid is bound to a DataTable.
   myTable = (DataTable) DataGrid1.DataSource;
   Console.WriteLine(myTable.Rows[myCell.RowNumber]
   [myCell.ColumnNumber]);
}


[C++] 
private:
   void PrintCellRowAndCol() {
      DataGridCell __gc *myCell;
      myCell = __box(DataGrid1->CurrentCell);
      Console::WriteLine(myCell->RowNumber);
      Console::WriteLine(myCell->ColumnNumber);
      // Prints the value of the cell through the DataTable.
      DataTable __gc *myTable;
      // Assumes the DataGrid is bound to a DataTable.
      myTable = dynamic_cast<DataTable *>(DataGrid1->DataSource);
      Console::WriteLine(myTable->Rows->Item[myCell->RowNumber]->Item[myCell->ColumnNumber]);
   };

[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.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

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

See Also

DataGridCell Members | System.Windows.Forms Namespace | CurrentCell | DataColumn | DataGrid | DataRow | ColumnNumber | RowNumber

Show:
© 2014 Microsoft