Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Determine Part Of DataGrid Clicked?

How-to

How to Determine Part Of DataGrid Clicked?

by  PankajBanga  Posted    (Edited  )

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!!!
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top