PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Help needed about strange behaviour of a datagridview and tooltip-VBForums
Results 1 to 17 of 17

Thread: [RESOLVED] Help needed about strange behaviour of a datagridview and tooltip

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Resolved [RESOLVED] Help needed about strange behaviour of a datagridview and tooltip

    While I was trying to get a tooltip to work on my DGV, I noticed that my DGV actually was already showing a pop-up when hovering over the header cells but only from 4th column and 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 the 4th column and on. The pop-up also contains the header cell text; very strange.

    What could be doing that? And how can I find where in the code is this happening? I went through the whole events for the DGV but they are not responsible. I searched the entire project for events like "mouseOver" and "Hover" but no indication. Also searched for "> 3" to see if there is somewhere that I am doing this for those column indices; no luck.

    Thanks for any tip
    Last edited by Grand; Aug 28th, 2019 at 03:50 AM.

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

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Dit you set the ToolTipText property for that column?
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    I am not sure. Maybe I did at some time. How will I check that? and by the way, the project does not ahve a tooltip control. I have deleted it but still the tip shows up. or it might be somethings else?

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

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Right click on the datagridview, Select edit columns.... double click on your column and look for the ToolTip property
    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: Help needed about strange behaviour of a datagridview and tooltip

    OK. I think I forgot to mention that my DGV is databound; sorry about that. This means there is no columns in design mode.

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

    Re: Help needed about strange behaviour of a datagridview and tooltip

    in that case we would have to see your code, and proberbly your disigner form designer file to see whats going on.
    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: Help needed about strange behaviour of a datagridview and tooltip

    I can prepare that but you won't be able to run it as it interact with multiple tables on a SQL database which I cannot provide to you. Is there a way around this?

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

    Re: Help needed about strange behaviour of a datagridview and tooltip

    The code is a good start to see whats going on. In the beginning i dont think we need the databse.
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  9. #9
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,039

    Re: Help needed about strange behaviour of a datagridview and tooltip

    not sure what your problem is, give this a try

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("col1")
            dt.Columns.Add("col2")
            dt.Rows.Add("1", "test1")
            dt.Rows.Add("2", "test2")
            dt.Rows.Add("3", "test3")
            dt.Rows.Add("4", "test4")
      
            DataGridView1.DataSource = dt
    
            For Each r As DataGridViewRow In DataGridView1.Rows
                If Not r.IsNewRow Then
                    For Each c As DataGridViewCell In r.Cells
                        If c.Value IsNot Nothing Then
                            c.ToolTipText = c.Value.ToString
                        End If
                    Next
                End If
            Next
    
        End Sub
    
      
    
        Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
    
            DataGridView1.Columns(0).HeaderCell.ToolTipText = "Col1 Header ToolTip"
            DataGridView1.Columns(1).HeaderCell.ToolTipText = "Col2 Header ToolTip"
    
    
    
            If e.ColumnIndex = Me.DataGridView1.Columns(1).Index AndAlso (e.Value IsNot Nothing) Then
    
                With Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
    
                    If e.Value.Equals("test1") Then
    
                        .ToolTipText = "< Tooltip 1 >"
    
                    ElseIf e.Value.Equals("test2") Then
    
                        .ToolTipText = "< Tooltip 2 > "
    
                    ElseIf e.Value.Equals("test3") Then
    
                        .ToolTipText = "< Tooltip 3 >"
    
                    ElseIf e.Value.Equals("test4") Then
    
                        .ToolTipText = "< Tooltip 4 >"
    
                    End If
    
                End With
    
            End If
        End Sub
    hth
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Quote Originally Posted by Goggy View Post
    The code is a good start to see whats going on. In the beginning i dont think we need the databse.
    thanks for helping out. Here is the code:Vbforums_2019-08-28.zip

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Quote Originally Posted by ChrisE View Post
    not sure what your problem is, give this a try

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim dt As New DataTable()
            dt.Columns.Add("col1")
            dt.Columns.Add("col2")
            dt.Rows.Add("1", "test1")
            dt.Rows.Add("2", "test2")
            dt.Rows.Add("3", "test3")
            dt.Rows.Add("4", "test4")
      
            DataGridView1.DataSource = dt
    
            For Each r As DataGridViewRow In DataGridView1.Rows
                If Not r.IsNewRow Then
                    For Each c As DataGridViewCell In r.Cells
                        If c.Value IsNot Nothing Then
                            c.ToolTipText = c.Value.ToString
                        End If
                    Next
                End If
            Next
    
        End Sub
    
      
    
        Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
    
            DataGridView1.Columns(0).HeaderCell.ToolTipText = "Col1 Header ToolTip"
            DataGridView1.Columns(1).HeaderCell.ToolTipText = "Col2 Header ToolTip"
    
    
    
            If e.ColumnIndex = Me.DataGridView1.Columns(1).Index AndAlso (e.Value IsNot Nothing) Then
    
                With Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
    
                    If e.Value.Equals("test1") Then
    
                        .ToolTipText = "< Tooltip 1 >"
    
                    ElseIf e.Value.Equals("test2") Then
    
                        .ToolTipText = "< Tooltip 2 > "
    
                    ElseIf e.Value.Equals("test3") Then
    
                        .ToolTipText = "< Tooltip 3 >"
    
                    ElseIf e.Value.Equals("test4") Then
    
                        .ToolTipText = "< Tooltip 4 >"
    
                    End If
    
                End With
    
            End If
        End Sub
    hth
    Thanks ChrisE. It worked on a fresh DGV but can't get it to work on my DGV. Also that I need to have a tooltip for header cells where I can get the content of the cell and then do something with it. I think this thread is to see if we can find out what my issue is. The other thread is more fitting to try a solution.

  12. #12
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,039

    Re: Help needed about strange behaviour of a datagridview and tooltip

    try this in the Form Load for HeaderCell

    Code:
     For Each co As DataGridViewColumn In DataGridView1.Columns
                co.HeaderCell.ToolTipText = co.HeaderCell.Value
            Next
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Quote Originally Posted by ChrisE View Post
    try this in the Form Load for HeaderCell

    Code:
     For Each co As DataGridViewColumn In DataGridView1.Columns
                co.HeaderCell.ToolTipText = co.HeaderCell.Value
            Next
    It didn't work. I think, it is because that I am overwrting it somewhere else and I cannot figure it out where.
    Also that I forgot to mention that the DGV content is dynamic/it changes based on the user selection of a combobox. So, we need to find a solution that looks at the current state of the DGV.
    Did you have a look at my code?

  14. #14
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,039

    Re: Help needed about strange behaviour of a datagridview and tooltip

    no I didn't look at your code, I will if this doesn't work

    this will read the HeaderCells to the Debug Window, see if they are correct
    use a Button
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim headers = (From header As DataGridViewColumn In _
                           DataGridView1.Columns.Cast(Of DataGridViewColumn)() _
                           Select header.HeaderText).ToArray
    
            Debug.Print(String.Join(";", headers))
            'or each Column in a new Line
            'Debug.Print(String.Join(vbNewLine, headers))
        End Sub
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Hi,
    It gives me the text of each column header of my current DGV. e.g. :

    Code:
    JFIM;ModuleCode;CourseCode;DocTitle;JBLX

  16. #16
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,253

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Quote Originally Posted by Grand View Post
    I then deleted the tooltip control to check if it has any effect but the pup-up still shows up on header cells from the 4th column and on. The pop-up also contains the header cell text; very strange.

    What could be doing that? And how can I find where in the code is this happening? I went through the whole events for the DGV but they are not responsible. I searched the entire project for events like "mouseOver" and "Hover" but no indication. Also searched for "> 3" to see if there is somewhere that I am doing this for those column indices; no luck.
    That's the normal behaviour of the DGV Control when the width of the text in the cell is wider than the cell itself. In my experience, you also get this default pop-up behaviour when the text does actually fit the cell's width, but only just barely fits.


    If you are happy to use the DGV's pop-up mechanism (as opposed to rolling your own with the ToolTip Class), and the DGV is bound, then you might want to look at the CellToolTipTextNeeded event.

    Something like the following example should work for you:
    vb.net Code:
    1. Private Sub DataGridView1_CellToolTipTextNeeded(sender As Object, e As DataGridViewCellToolTipTextNeededEventArgs) Handles DataGridView1.CellToolTipTextNeeded
    2.     Dim dgv = DirectCast(sender, DataGridView)
    3.  
    4.     If e.RowIndex = -1 AndAlso e.ColumnIndex <> -1 Then
    5.         e.ToolTipText = dgv.Columns(e.ColumnIndex).HeaderText & vbCrLf & "this is a column header"
    6.     Else
    7.         e.ToolTipText = "Not a column header cell"
    8.     End If
    9. End Sub

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2018
    Posts
    325

    Re: Help needed about strange behaviour of a datagridview and tooltip

    Quote Originally Posted by Inferrd View Post
    That's the normal behaviour of the DGV Control when the width of the text in the cell is wider than the cell itself. In my experience, you also get this default pop-up behaviour when the text does actually fit the cell's width, but only just barely fits.


    If you are happy to use the DGV's pop-up mechanism (as opposed to rolling your own with the ToolTip Class), and the DGV is bound, then you might want to look at the CellToolTipTextNeeded event.

    Something like the following example should work for you:
    vb.net Code:
    1. Private Sub DataGridView1_CellToolTipTextNeeded(sender As Object, e As DataGridViewCellToolTipTextNeededEventArgs) Handles DataGridView1.CellToolTipTextNeeded
    2.     Dim dgv = DirectCast(sender, DataGridView)
    3.  
    4.     If e.RowIndex = -1 AndAlso e.ColumnIndex <> -1 Then
    5.         e.ToolTipText = dgv.Columns(e.ColumnIndex).HeaderText & vbCrLf & "this is a column header"
    6.     Else
    7.         e.ToolTipText = "Not a column header cell"
    8.     End If
    9. End Sub
    That is great. than you so much for clearing that up. Also your example solved my challenge as well.
    Thanks again.

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