DataGridCell 結構

定義

識別格線中的儲存格。

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

範例

下列範例會將 DataGridCell 指派給 CurrentCellSystem.Windows.Forms.DataGrid ,並傳回所選取儲存格的資料行和資料列編號。 儲存在 中的 DataTable 值也會使用 物件的 DataGridCell RowNumberColumnNumber 來列印。

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可以與控制項的 CurrentCell 屬性搭配 System.Windows.Forms.DataGrid 使用,以取得或設定任何儲存格的值。 將 System.Windows.Forms.DataGrid 控制項的 CurrentCell 屬性設定為 DataGridCell ,會使焦點移至 所 DataGridCell 指定的儲存格。

建構函式

DataGridCell(Int32, Int32)

初始化 DataGridCell 類別的新執行個體。

屬性

ColumnNumber

取得或設定 DataGrid 控制項中的資料行編號。

RowNumber

取得或設定 DataGrid 控制項中的資料列編號。

方法

Equals(Object)

取得值,表示 DataGridCell 是否與第二個 DataGridCell 相同。

GetHashCode()

取得可加入 Hashtable 的雜湊值。

ToString()

取得儲存格的資料列編號和資料行編號。

適用於

另請參閱