DataGrid.CurrentCell 属性

获取或设置具有焦点的单元格。设计时不可用。

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

语法

声明
Public Property CurrentCell As DataGridCell
用法
Dim instance As DataGrid
Dim value As DataGridCell

value = instance.CurrentCell

instance.CurrentCell = value
public DataGridCell CurrentCell { get; set; }
public:
property DataGridCell CurrentCell {
    DataGridCell get ();
    void set (DataGridCell value);
}
/** @property */
public DataGridCell get_CurrentCell ()

/** @property */
public void set_CurrentCell (DataGridCell value)
public function get CurrentCell () : DataGridCell

public function set CurrentCell (value : DataGridCell)

属性值

具有焦点的 DataGridCell

备注

设置 CurrentCell 属性将导致网格滚动,并显示该单元格是否已经可见。

示例

下面的代码示例演示如何设置和获取当前单元格。

Private Sub SetCellWithFocus(ByVal myGrid As DataGrid)
    ' Set the current cell to cell 1, row 1.
    myGrid.CurrentCell = New DataGridCell(1,1)
 End Sub
 
 Private Sub DataGrid1_GotFocus(ByVal Sender As Object, ByVal e As EventArgs)
    Console.WriteLine(DataGrid1.CurrentCell.ColumnNumber & " " & _
       DataGrid1.CurrentCell.RowNumber)
 End Sub
    
private void SetCellWithFocus(DataGrid myGrid)
 {
    // Set the current cell to cell1, row 1.
    myGrid.CurrentCell = new DataGridCell(1,1);
 }
 
 private void dataGrid1_GotFocus(object sender, EventArgs e)
 {
    Console.WriteLine(dataGrid1.CurrentCell.ColumnNumber + 
    " " + dataGrid1.CurrentCell.RowNumber);
 }
    
private:
   void SetCellWithFocus( DataGrid^ myGrid )
   {
      // Set the current cell to cell1, row 1.
      myGrid->CurrentCell = DataGridCell( 1, 1 );
   }

   void dataGrid1_GotFocus( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      Console::WriteLine( "{0} {1}", dataGrid1->CurrentCell.ColumnNumber,
         dataGrid1->CurrentCell.RowNumber );
   }
private void SetCellWithFocus(DataGrid myGrid)
{
    // Set the current cell to cell1, row 1.
    myGrid.set_CurrentCell(new DataGridCell(1, 1));
} //SetCellWithFocus

private void dataGrid1_GotFocus(Object sender, EventArgs e)
{
    Console.WriteLine(dataGrid1.get_CurrentCell().get_ColumnNumber()
        + " " + dataGrid1.get_CurrentCell().get_RowNumber());
} //dataGrid1_GotFocus

平台

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

请参见

参考

DataGrid 类
DataGrid 成员
System.Windows.Forms 命名空间
DataGridCell
FirstVisibleColumn