Export (0) Print
Expand All

DataGrid.HitTest Method

Gets information about the System.Windows.Forms.DataGrid control at a specified point on the screen.

Overload List

Gets information, such as row and column number of a clicked point on the grid, about the grid using a specific Point.

[Visual Basic] Overloads Public Function HitTest(Point) As HitTestInfo
[C#] public HitTestInfo HitTest(Point);
[C++] public: HitTestInfo* HitTest(Point);
[JScript] public function HitTest(Point) : HitTestInfo;

Gets information, such as row and column number of a clicked point on the grid, using the x and y coordinate passed to the method.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function HitTest(Integer, Integer) As HitTestInfo
[C#] public HitTestInfo HitTest(int, int);
[C++] public: HitTestInfo* HitTest(int, int);
[JScript] public function HitTest(int, int) : HitTestInfo;

Example

[Visual Basic] The following example uses the HitTest method in an event that occurs when the user clicks in the grid.

[Visual Basic] Note   This example shows how to use one of the overloaded versions of HitTest. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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
 

[C#, C++, JScript] No example is available for C#, C++, or JScript. To view a Visual Basic example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataGrid Class | DataGrid Members | System.Windows.Forms Namespace

Show:
© 2015 Microsoft