INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How-to

How to Determine Part Of DataGrid Clicked? by PankajBanga
Posted: 12 Jun 03 (Edited 12 Jun 03)


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.

  • Please add StatusBar control (with one Panel) on your Form before running the code.


  • 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!!!

    Back to Visual Basic (Microsoft) VB.NET FAQ Index
    Back to Visual Basic (Microsoft) VB.NET Forum

    My Archive

    Resources

    Close Box

    Join Tek-Tips® Today!

    Join your peers on the Internet's largest technical computer professional community.
    It's easy to join and it's free.

    Here's Why Members Love Tek-Tips Forums:

    Register now while it's still free!

    Already a member? Close this window and log in.

    Join Us             Close