DataGrid.HitTest Metod

Definition

Hämtar information om DataGrid kontrollen vid en angiven punkt på skärmen.

Överlagringar

Name Description
HitTest(Int32, Int32)

Hämtar information, till exempel rad- och kolumnnummer för en klickad punkt i rutnätet, med hjälp av koordinaten x och y som skickas till metoden.

HitTest(Point)

Hämtar information, till exempel rad- och kolumnnummer för en klickad punkt i rutnätet, om rutnätet med hjälp av en specifik Point.

HitTest(Int32, Int32)

Källa:
DataGrid.cs
Källa:
DataGrid.cs

Hämtar information, till exempel rad- och kolumnnummer för en klickad punkt i rutnätet, med hjälp av koordinaten x och y som skickas till metoden.

public:
 System::Windows::Forms::DataGrid::HitTestInfo ^ HitTest(int x, int y);
public System.Windows.Forms.DataGrid.HitTestInfo HitTest(int x, int y);
member this.HitTest : int * int -> System.Windows.Forms.DataGrid.HitTestInfo
Public Function HitTest (x As Integer, y As Integer) As DataGrid.HitTestInfo

Parametrar

x
Int32

Koordinatens vågräta position.

y
Int32

Koordinatens lodräta position.

Returer

En DataGrid.HitTestInfo som innehåller information om den klickade delen av rutnätet.

Exempel

I följande kodexempel används HitTest metoden i en händelse som inträffar när användaren klickar i rutnätet.

Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim myGrid As DataGrid = CType(sender, DataGrid)
    Dim hti As System.Windows.Forms.DataGrid.HitTestInfo
    hti = myGrid.HitTest(e.X, e.Y)
    Select Case hti.Type
    Case System.Windows.Forms.DataGrid.HitTestType.None 
       Console.WriteLine("You clicked the background.")
    Case System.Windows.Forms.DataGrid.HitTestType.Cell 
       Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
       Console.WriteLine("You clicked the column header for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowHeader 
       Console.WriteLine("You clicked the row header for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
       Console.WriteLine("You clicked the column resizer for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowResize 
       Console.WriteLine("You clicked the row resizer for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.Caption
       Console.WriteLine("You clicked the caption")
    Case System.Windows.Forms.DataGrid.HitTestType.ParentRows 
       Console.WriteLine("You clicked the parent row")
    End Select
 
 End Sub

Kommentarer

DataGrid.HitTestInfo används tillsammans med metoden HitTest för kontrollen System.Windows.Forms.DataGrid för att avgöra vilken del av en System.Windows.Forms.DataGrid kontroll som användaren har klickat på. DataGrid.HitTestInfo Innehåller raden, kolumnen och en del av rutnätet som klickades. Dessutom returnerar egenskapen Type en DataGrid.HitTestType uppräkning.

Metoden HitTest tar ett x- och y-argument som tillhandahålls av System.Windows.Forms.DataGrid-kontrollens DragDrop. DragEnter, DragOver, MouseDown, MouseMove, MouseUp och MouseWheel händelser.

Se även

Gäller för

HitTest(Point)

Källa:
DataGrid.cs
Källa:
DataGrid.cs

Hämtar information, till exempel rad- och kolumnnummer för en klickad punkt i rutnätet, om rutnätet med hjälp av en specifik Point.

public:
 System::Windows::Forms::DataGrid::HitTestInfo ^ HitTest(System::Drawing::Point position);
public System.Windows.Forms.DataGrid.HitTestInfo HitTest(System.Drawing.Point position);
member this.HitTest : System.Drawing.Point -> System.Windows.Forms.DataGrid.HitTestInfo
Public Function HitTest (position As Point) As DataGrid.HitTestInfo

Parametrar

position
Point

En Point som representerar enstaka x,y-koordinat.

Returer

En DataGrid.HitTestInfo som innehåller specifik information om rutnätet.

Exempel

I följande kodexempel används HitTest metoden i när en användare klickar på ett rutnät.

Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
    Dim hti As DataGrid.HitTestInfo
    hti = grid.HitTest(New Point(e.X, e.Y))
    Select Case hti.Type
    Case System.Windows.Forms.DataGrid.HitTestType.None 
       Console.WriteLine("You clicked the background.")
    Case System.Windows.Forms.DataGrid.HitTestType.Cell 
       Console.WriteLine("You clicked cell at row " & hti.Row & ", col " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader
       Console.WriteLine("You clicked the column header for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowHeader 
       Console.WriteLine("You clicked the row header for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.ColumnResize
       Console.WriteLine("You clicked the column resizer for column " & hti.Column)
    Case System.Windows.Forms.DataGrid.HitTestType.RowResize 
       Console.WriteLine("You clicked the row resizer for row " & hti.Row)
    Case System.Windows.Forms.DataGrid.HitTestType.Caption
       Console.WriteLine("You clicked the caption")
    Case System.Windows.Forms.DataGrid.HitTestType.ParentRows 
       Console.WriteLine("You clicked the parent row")
    End Select
 End Sub

Kommentarer

DataGrid.HitTestInfo används tillsammans med metoden HitTest för kontrollen System.Windows.Forms.DataGrid för att avgöra vilken del av en System.Windows.Forms.DataGrid kontroll som användaren har klickat på. DataGrid.HitTestInfo Innehåller raden, kolumnen och en del av rutnätet som klickades. Dessutom returnerar egenskapen Type en DataGrid.HitTestType uppräkning.

Metoden HitTest tar ett x- och y-argument som tillhandahålls av System.Windows.Forms.DataGrid-kontrollens DragDrop. DragEnter, DragOver, MouseDown, MouseMove, MouseUp och MouseWheel händelser.

Se även

Gäller för