dcsimg
Results 1 to 8 of 8

Thread: [RESOLVED] ToolTipText on header cells of a datagridview

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Resolved [RESOLVED] ToolTipText on header cells of a datagridview

    Hi,
    I am struggling to get a tooltip to show up when a mouse courser is hovering over the header cells of a datagirdview.

    I am not sure which event of the DGV shall be used and how to read the header cell text (I am using the text to get some info from a database) and show some info in a tooltiptext pop-up.

    Thanks in advance for the help.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,913

    Re: ToolTipText on header cells of a datagridview

    Handle the MouseHover event, because you generally display a tooltip when the mouse hovers, i.e. sits still over something. In the event handler, you can call the HitTest method to get information about where the mouse pointer is located. If it's over a header cell, get the information for that cell and display it by calling the Show method of your ToolTip.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: ToolTipText on header cells of a datagridview

    Thanks for the guidance.
    I tried this so far, but am getting no result
    Code:
        
    Private Sub DataGridView1_MouseHover(sender As Object, e As EventArgs) Handles DataGridView1.MouseHover    
    Dim Pos = DataGridView1.PointToClient(Cursor.Position)
            Dim HitTest As DataGridView.HitTestInfo = DataGridView1.HitTest(Pos.X, Pos.Y)
    
            If HitTest.Type = DataGridViewHitTestType.Cell Then
                ToolTip1.Show("Testing tool tip", DataGridView1, Pos.X, Pos.Y)
            End If
    End Sub

  4. #4
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    158

    Re: ToolTipText on header cells of a datagridview

    I think your on the right track....
    Just use DataGridViewHitTestType.ColumnHeader or DataGridViewHitTestType.RowHeade instead of DataGridViewHitTestType.Cell

    Code:
        Private Sub DataGridView1_MouseHover(sender As Object, e As EventArgs) Handles DataGridView1.MouseHover
            Dim P As Drawing.Point = Me.DataGridView1.PointToClient(MousePosition)
            Dim HitTest As DataGridView.HitTestInfo = Me.DataGridView1.HitTest(P.X, P.Y)
    
            If HitTest.Type = DataGridViewHitTestType.ColumnHeader Or HitTest.Type = DataGridViewHitTestType.RowHeader Then
                Debug.Print("Bingo")
            End If
        End Sub
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: ToolTipText on header cells of a datagridview

    Thank you for helping out. I tried your code but nothing happened. The code does not produces true for the if statement.
    However, I noticed that my DGV actually is showing a pop-up when hovering over the header cells but only from column 4 an onward. I could not see anywhere in the code that I was doing it (I might have forgotten having done that already). I then deleted the tooltip control to check if it has any effect but the pup-up still shows up on header cells from column 4 an on. The pop-up also contains the header cell text; very strange.

    I asked for help about this strange thing in another thread.

  6. #6
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    158

    Re: ToolTipText on header cells of a datagridview

    The code i posted prints Bingo in the Output window.
    I tested it again just to be sure... You might have overlooked the Output window?
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: ToolTipText on header cells of a datagridview

    Thanks for following up. I have checked, the code does not produces true for the if statement so it never gets to the "print" thing. I ahve tried to hover on different places but no luck.
    Anyway, I think, if you have time, let's try to solve the issue on my other related thread. I say this because somehow the project is actually doing what I originally wanted but without me knowing why, where and how; I must have forgotten.
    Thanks again

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: ToolTipText on header cells of a datagridview

    The challenge was solved by "Inferrd" at here
    Thank you for your time and guidance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width