|
-
Dec 19th, 2007, 01:23 AM
#1
Thread Starter
Junior Member
[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
-
Dec 19th, 2007, 07:02 AM
#2
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
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
-
Dec 19th, 2007, 10:54 AM
#3
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!
-
Dec 19th, 2007, 01:57 PM
#4
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)
-
Dec 19th, 2007, 03:42 PM
#5
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
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
-
Dec 19th, 2007, 06:24 PM
#6
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.
-
Dec 30th, 2007, 10:43 PM
#7
Thread Starter
Junior Member
Re: combobox with tooltips for each item
-
Dec 31st, 2007, 07:02 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|