Condividi tramite


DataGrid.HitTest Metodo

Definizione

Ottiene informazioni sul DataGrid controllo in corrispondenza di un punto specificato sullo schermo.

Overload

Nome Descrizione
HitTest(Int32, Int32)

Ottiene informazioni, ad esempio il numero di riga e di colonna di un punto selezionato nella griglia, utilizzando la coordinata x e y passata al metodo .

HitTest(Point)

Ottiene informazioni, ad esempio il numero di riga e di colonna di un punto selezionato nella griglia, sulla griglia usando un oggetto specifico Point.

HitTest(Int32, Int32)

Origine:
DataGrid.cs
Origine:
DataGrid.cs

Ottiene informazioni, ad esempio il numero di riga e di colonna di un punto selezionato nella griglia, utilizzando la coordinata x e y passata al metodo .

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

Parametri

x
Int32

Posizione orizzontale della coordinata.

y
Int32

Posizione verticale della coordinata.

Restituisce

Oggetto DataGrid.HitTestInfo contenente informazioni sulla parte selezionata della griglia.

Esempio

Nell'esempio di codice seguente viene usato il HitTest metodo in un evento che si verifica quando l'utente fa clic nella griglia.

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

Commenti

L'oggetto DataGrid.HitTestInfo, insieme al HitTest metodo del System.Windows.Forms.DataGrid controllo , viene utilizzato per determinare quale parte di un System.Windows.Forms.DataGrid controllo ha fatto clic sull'utente. DataGrid.HitTestInfo Contiene la riga, la colonna e la parte della griglia su cui è stato fatto clic. Inoltre, la Type proprietà restituisce un'enumerazione DataGrid.HitTestType .

Il HitTest metodo accetta un argomento x e y fornito dagli eventi , MouseUpMouseMoveDragEnterMouseDownDragOvere MouseWheel del System.Windows.Forms.DataGridDragDropcontrollo.

Vedi anche

Si applica a

HitTest(Point)

Origine:
DataGrid.cs
Origine:
DataGrid.cs

Ottiene informazioni, ad esempio il numero di riga e di colonna di un punto selezionato nella griglia, sulla griglia usando un oggetto specifico 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

Parametri

position
Point

Oggetto Point che rappresenta una singola coordinata x,y.

Restituisce

Oggetto DataGrid.HitTestInfo che contiene informazioni specifiche sulla griglia.

Esempio

L'esempio di codice seguente usa il HitTest metodo in si verifica quando un utente fa clic su una griglia.

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

Commenti

L'oggetto DataGrid.HitTestInfo, insieme al HitTest metodo del System.Windows.Forms.DataGrid controllo , viene utilizzato per determinare quale parte di un System.Windows.Forms.DataGrid controllo ha fatto clic sull'utente. DataGrid.HitTestInfo Contiene la riga, la colonna e la parte della griglia su cui è stato fatto clic. Inoltre, la Type proprietà restituisce un'enumerazione DataGrid.HitTestType .

Il HitTest metodo accetta un argomento x e y fornito dagli eventi , MouseUpMouseMoveDragEnterMouseDownDragOvere MouseWheel del System.Windows.Forms.DataGridDragDropcontrollo.

Vedi anche

Si applica a