Share via


DataGrid.CurrentRowIndex 属性

获取或设置当前具有焦点的行的索引。

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

语法

声明
Public Property CurrentRowIndex As Integer
用法
Dim instance As DataGrid
Dim value As Integer

value = instance.CurrentRowIndex

instance.CurrentRowIndex = value
public int CurrentRowIndex { get; set; }
public:
property int CurrentRowIndex {
    int get ();
    void set (int value);
}
/** @property */
public int get_CurrentRowIndex ()

/** @property */
public void set_CurrentRowIndex (int value)
public function get CurrentRowIndex () : int

public function set CurrentRowIndex (value : int)

属性值

当前行的从零开始的索引。

异常

异常类型 条件

Exception

没有 CurrencyManager

备注

CurrentRowIndex 属性设置为其当前值以外的值将滚动控件,以使指定行显示在视图中。

即使您正在查看子表行,CurrentRowIndex 属性仍允许您循环访问父表的行。例如,如果正在查看某子表,增加 CurrentRowIndex 将导致 System.Windows.Forms.DataGrid 显示链接到父表的子表中的下一组记录。

如果用户正在查看父表或者没有子关系的表,则该属性返回当前行的以零开始的索引。

示例

下面的代码示例返回 CurrentRowIndex

Private Sub GetSelectedIndex(ByVal myGrid As DataGrid)
    Console.WriteLine(myGrid.CurrentRowIndex)
 End Sub
 
 Private Sub SetSelectedIndex(ByVal myGrid As DataGrid, ByVal selIndex As Integer)
    myGrid.CurrentRowIndex= selIndex
 End Sub
 
private void GetSelectedIndex(DataGrid myGrid){
    Console.WriteLine(myGrid.CurrentRowIndex);
 }
 
 private void SetSelectedIndex(DataGrid myGrid, int selIndex){
    myGrid.CurrentRowIndex = selIndex;
 }
 
private:
   void GetSelectedIndex( DataGrid^ myGrid )
   {
      Console::WriteLine( myGrid->CurrentRowIndex );
   }

   void SetSelectedIndex( DataGrid^ myGrid, int selIndex )
   {
      myGrid->CurrentRowIndex = selIndex;
   }
private void GetSelectedIndex(DataGrid myGrid)
{
    Console.WriteLine(myGrid.get_CurrentRowIndex());
} //GetSelectedIndex

private void SetSelectedIndex(DataGrid myGrid, int selIndex)
{
    myGrid.set_CurrentRowIndex(selIndex);
} //SetSelectedIndex

平台

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 命名空间
CurrencyManager 类