DataGrid.HitTestInfo.Row 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取用户单击的行号。
public:
property int Row { int get(); };
public int Row { get; }
member this.Row : int
Public ReadOnly Property Row As Integer
属性值
单击的行号。
示例
以下示例通过在 控件的 事件中MouseDown调用 HitTest 方法,打印单击的行和列的System.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。