DataGridCell 结构

定义

标识网格中的单元格。Identifies a cell in the grid.

public value class DataGridCell
public struct DataGridCell
type DataGridCell = struct
Public Structure DataGridCell
继承
DataGridCell

示例

下面的示例将分配 DataGridCellCurrentCell 的, System.Windows.Forms.DataGrid 并返回所选单元格的列号和行号。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. 中存储的值 DataTable 还使用 DataGridCell 对象的和进行打印 RowNumber ColumnNumberThe value stored in the DataTable is also printed using the DataGridCell object's RowNumber and ColumnNumber.

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 = dynamic_cast<DataTable^>(DataGrid1->DataSource);
   Console::WriteLine( myTable->Rows[ myCell->RowNumber ][ myCell->ColumnNumber ] );
}

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

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

注解

DataGridCell可以与 System.Windows.Forms.DataGrid 控件的属性结合使用 CurrentCell ,以获取或设置任意单元格的值。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. 如果将 System.Windows.Forms.DataGrid 控件的 CurrentCell 属性设置为,则 DataGridCell 会导致焦点移到由指定的单元格 DataGridCellSetting the System.Windows.Forms.DataGrid control's CurrentCell property to a DataGridCell causes the focus to move to the cell specified by the DataGridCell.

构造函数

DataGridCell(Int32, Int32)

初始化 DataGridCell 类的新实例。Initializes a new instance of the DataGridCell class.

属性

ColumnNumber

获取或设置 DataGrid 控件中某列的列号。Gets or sets the number of a column in the DataGrid control.

RowNumber

获取或设置 DataGrid 控件中某行的行号。Gets or sets the number of a row in the DataGrid control.

方法

Equals(Object)

获取一个值,该值指示 DataGridCell 是否与第二个 DataGridCell 完全相同。Gets a value indicating whether the DataGridCell is identical to a second DataGridCell.

GetHashCode()

获取一个可被添加到 Hashtable 的哈希值。Gets a hash value that can be added to a Hashtable.

ToString()

获取单元格的行号和列号。Gets the row number and column number of the cell.

适用于

另请参阅