共用方式為


DataGrid.HitTestInfo.Row 屬性

定義

取得使用者按下的資料列的編號。

public:
 property int Row { int get(); };
public int Row { get; }
member this.Row : int
Public ReadOnly Property Row As Integer

屬性值

按下的資料列的編號。

範例

下列範例會從 控制項的 事件 System.Windows.Forms.DataGridMouseDown 呼叫 HitTest 方法,以列印按下的資料列和資料行數目。 這會傳回 DataGrid.HitTestInfo 物件。

private:
   void dataGrid1_MouseDown( Object^ /*sender*/,
      System::Windows::Forms::MouseEventArgs^ e )
   {
      String^ newLine = "\n";
      Console::WriteLine( newLine );
      System::Windows::Forms::DataGrid::HitTestInfo^ myHitTest;
      // Use the DataGrid control's HitTest method with the x and y properties.
      myHitTest = dataGrid1->HitTest( e->X, e->Y );
      Console::WriteLine( "Column {0}", myHitTest->Column );
      Console::WriteLine( "Row {0}", myHitTest->Row );
   }
private void dataGrid1_MouseDown
(object sender, System.Windows.Forms.MouseEventArgs e)
{
   string newLine = "\n";
   Console.WriteLine(newLine);
   System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
   // Use the DataGrid control's HitTest method with the x and y properties.
   myHitTest = dataGrid1.HitTest(e.X,e.Y);
   Console.WriteLine("Column " + myHitTest.Column);
   Console.WriteLine("Row " + myHitTest.Row);
}
Private Sub dataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Dim newLine As String = ControlChars.Cr
    Console.WriteLine(newLine)
    Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo
    ' Use the DataGrid control's HitTest method with the x and y properties.
    myHitTest = dataGrid1.HitTest(e.X, e.Y)
    Console.WriteLine(("Column " & myHitTest.Column))
    Console.WriteLine(("Row " & myHitTest.Row))
End Sub

備註

如果座標不是儲存格,屬性會傳回 -1。 如果座標是 RowHeader ,則 屬性會傳回標頭的資料列編號,但 Column 屬性會傳回 -1。

適用於

另請參閱