This sample illustrates how to use the HitTest method to determine which part of DataGrid the user clicked. It calls the HitTest method on MouseUp event handler, which returns a DataGrid.HitTestInfo object that contains information about a part of the DataGrid at a specified coordinate.
Features
Determines whether the user has clicked the Background, Caption, Cell, Column Header, Column resizer, Row Header or Row resizer on the DataGrid.
[li]Please add StatusBar control (with one Panel) on your Form before running the code.[/li]
Private Sub onmyDataGridMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseUp
Dim hit As System.Windows.Forms.DataGrid.HitTestInfo
hit = DataGrid1.HitTest(e.X, e.Y)
Dim message As String = "You clicked "
Select Case hit.Type
Case Windows.Forms.DataGrid.HitTestType.None
message &= "the BACKGROUND"
Case Windows.Forms.DataGrid.HitTestType.Caption
message &= "the CAPTION"
Case Windows.Forms.DataGrid.HitTestType.Cell
message &= "cell at ROW " & hit.Row & ", COLUMN " & hit.Column
Case Windows.Forms.DataGrid.HitTestType.ColumnHeader
message &= "the COLUMN HEADER for column " & hit.Column
Case Windows.Forms.DataGrid.HitTestType.ColumnResize
message &= "the COLUMN RESIZER for column " & hit.Column
Case Windows.Forms.DataGrid.HitTestType.RowHeader
message &= "the ROW HEADER for row " & hit.Row
Case Windows.Forms.DataGrid.HitTestType.RowResize
message &= "the ROW RESIZER for row " & hit.Row
End Select
StatusBar1.Panels(0).Text = message
End Sub
If you find the sample useful, please don't forget to Rate this and other samples. Your feedback will be much appreciated and valued and will keep me triggering. GOOD LUCK!!!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.