Results 1 to 8 of 8

Thread: [RESOLVED] combobox with tooltips for each item

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    20

    Resolved [RESOLVED] combobox with tooltips for each item

    how can i display tooltips for each of the item in the list of the combobox when i hover my mouse to each of the items? example like in the link below but its in visual c++

    http://www.codeguru.com/cpp/controls...cle.php/c4949/

    please kindly point me a direction if any of you know how to do this. thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: combobox with tooltips for each item

    there is probably better ways to do this, but this might give you a start
    vb Code:
    1. Private Sub Timer1_Timer()
    2. ret = SendMessage(Combo1.hwnd, CB_GETCURSEL, 0, 0)
    3. If Not ret = -1 Then Label1 = "display " & ret
    4. End Sub
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: combobox with tooltips for each item

    You can reference the ListIndex or the List.Text property to fire the ToolTip. Here's code that reads the Combo text and fires the correct ToolTip when the item is clicked.

    Edit: I didn't choose the MouseMove event for this code because the ComboBox doesn't support this event. I discovered that the ToolTip code can be placed in the Form MouseMove event and it will work! I think it's a better choice than the clickEvent.
    Code:
    Private Sub Form_Load()
       Combo1.AddItem "Hello"
       Combo1.AddItem "World"
    End Sub
    
    
    Private Sub Combo1_Click()
       If Combo1.Text = "Hello" Then Combo1.ToolTipText = "You picked Hello"
       If Combo1.Text = "World" Then Combo1.ToolTipText = "You picked World"
    End Sub
    Last edited by CDRIVE; Dec 19th, 2007 at 11:09 AM. Reason: Discovered something!

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: combobox with tooltips for each item

    If you want to add tooltips to the dropped combobox, then subclassing will be needed along with API tool tips. A lot of work honestly.

    1. Why subclassing? The dropdown portion of the combobox (really an API listbox) does not fire events to VB -- no mousemove events. So you may have to subclass the hWnd of that dropped listbox to get mouse move events.

    2. Since that listbox hWnd is not a VB control, you can't use .Tooltip properties. You will need to create tooltips via APIs.

    3. The following message may be needed to determine what the tooltip should be: LB_ITEMFROMPOINT - to return listitem index where cursor is over and this should translate to combo1.List(x)

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: combobox with tooltips for each item

    with my example above you can also check the dropped down state of the combo so the label will display nothing when the dropdown is closed, it wiould be easy to set the tooltiptext from that code, but i do not know how to show the tooltip while the box is dropped down
    vb Code:
    1. Private Sub Timer1_Timer()
    2. If SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0, 0) Then
    3.     ret = SendMessage(Combo1.hwnd, CB_GETCURSEL, 0, 0)
    4.     If Not ret = -1 Then Label1 = "display " & ret
    5.     Else: Label1 = ""
    6. End If
    7. End Sub

    you can enable and disable the timer in the combos got and lost focus events
    Last edited by westconn1; Dec 19th, 2007 at 03:52 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: combobox with tooltips for each item

    My apologies. I didn't realize that you needed to trigger the ToolTip while the ComboBox was dropped down.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2007
    Posts
    20

    Re: combobox with tooltips for each item

    thx for your helps guys.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] combobox with tooltips for each item

    see also wokas custom tooltips codes /tutorial in the vb6 code bank, i think there is example to do exactly what you are asking
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width