[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
Re: combobox with tooltips for each item
there is probably better ways to do this, but this might give you a start
vb Code:
Private Sub Timer1_Timer()
ret = SendMessage(Combo1.hwnd, CB_GETCURSEL, 0, 0)
If Not ret = -1 Then Label1 = "display " & ret
End Sub
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
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)
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:
Private Sub Timer1_Timer()
If SendMessage(Combo1.hwnd, CB_GETDROPPEDSTATE, 0, 0) Then
ret = SendMessage(Combo1.hwnd, CB_GETCURSEL, 0, 0)
If Not ret = -1 Then Label1 = "display " & ret
Else: Label1 = ""
End If
End Sub
you can enable and disable the timer in the combos got and lost focus events
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.
Re: combobox with tooltips for each item
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