DataGrid.CurrentRowIndex 屬性

定義

取得或設定目前具有焦點之資料列的索引。

public:
 property int CurrentRowIndex { int get(); void set(int value); };
[System.ComponentModel.Browsable(false)]
public int CurrentRowIndex { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.CurrentRowIndex : int with get, set
Public Property CurrentRowIndex As Integer

屬性值

Int32

目前資料列以零起始的索引。

屬性

例外狀況

範例

下列程式碼範例會傳 CurrentRowIndex 回 。

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.CurrentRowIndex);
 }
 
 private void SetSelectedIndex(DataGrid myGrid, int selIndex){
    myGrid.CurrentRowIndex = selIndex;
 }
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

備註

CurrentRowIndex 屬性設定為目前值以外的值會捲動控制項,讓指定的資料列處於檢視中。

屬性 CurrentRowIndex 可讓您逐一查看父資料表的資料列,即使您正在檢視子資料工作表資料列也一樣。 例如,如果您要檢視子資料工作表,遞 CurrentRowIndex 增 會導致 System.Windows.Forms.DataGrid 在連結到父資料表的子資料工作表中顯示下一組記錄。

如果使用者正在檢視父資料表,或沒有子關聯性資料表的資料表,則 屬性會傳回目前資料列以零起始的索引。

適用於

另請參閱