DataGrid.HitTestInfo.Row DataGrid.HitTestInfo.Row DataGrid.HitTestInfo.Row DataGrid.HitTestInfo.Row Property

定义

获取用户单击的行号。Gets the number of the row the user has clicked.

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

属性值

单击的行号。The number of the clicked row.

示例

下面的示例通过从HitTest System.Windows.Forms.DataGrid控件的MouseDown事件中调用方法, 打印所单击的行和列的数目。The following example prints the number of the clicked row and column by calling the HitTest method from within the MouseDown event of a System.Windows.Forms.DataGrid control. 这会返回DataGrid.HitTestInfo一个对象。This returns a DataGrid.HitTestInfo object.

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 'dataGrid1_MouseDown

注解

如果该坐标不是单元格, 则该属性返回-1。If the coordinate is not a cell, the property returns -1. 如果坐标为RowHeader, 则属性返回标头的行号, Column但属性将返回-1。If the coordinate is a RowHeader, the property returns the row number of the header, but the Column property will return -1.

适用于

另请参阅