DataGrid.HitTestInfo.Row プロパティ

定義

ユーザーがクリックした行の番号を取得します。

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

プロパティ値

クリックされた行の番号。

次の例では、コントロールの イベント内から メソッドを呼び出HitTestして、クリックした行と列の数をMouseDownSystem.Windows.Forms.DataGrid出力します。 これにより、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 を返します。

適用対象

こちらもご覧ください