DataGridCell 结构

标识网格中的单元格。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Structure DataGridCell
用法
Dim instance As DataGridCell
public struct DataGridCell
public value class DataGridCell
public final class DataGridCell extends ValueType
JScript 支持使用结构,但不支持进行新的声明。

备注

DataGridCell 可以与 System.Windows.Forms.DataGrid 控件的 CurrentCell 属性一起使用以获取或设置任何单元格的值。将 System.Windows.Forms.DataGrid 控件的 CurrentCell 属性设置为 DataGridCell 可使焦点移动到 DataGridCell 所指定的单元格。

示例

下面的示例将 DataGridCell 分配给 System.Windows.Forms.DataGridCurrentCell,并返回所选单元格的列号和行号。同时使用 DataGridCell 对象的 RowNumberColumnNumber 打印存储在 DataTable 中的值。

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
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]);
}
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.get_CurrentCell();
    Console.WriteLine(myCell.get_RowNumber());
    Console.WriteLine(myCell.get_ColumnNumber());
    // Prints the value of the cell through the DataTable.
    DataTable myTable;
    // Assumes the DataGrid is bound to a DataTable.
    myTable = (DataTable)(dataGrid1.get_DataSource());
    Console.WriteLine(myTable.get_Rows().
        get_Item(myCell.get_RowNumber()).
        get_Item(myCell.get_ColumnNumber()));
} //PrintCellRowAndCol

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataGridCell 成员
System.Windows.Forms 命名空间
DataGrid.CurrentCell 属性
DataColumn
DataGrid 类
DataRow
ColumnNumber
RowNumber