Combobox events (userform)

Gettingbetter

Well-known Member
Joined
Oct 12, 2004
Messages
602
Hello everyone, Happy new year.

I've been trying to solve this all morning and have had some near misses and some disaterous API attempts (my computer has crashed more times than a dogem).

So finally I have resolved to ask the board.

I am trying to show the equivalent of a ControlTipText on a combobox dropdown. By this I mean if my combobox has 10 items visible on the dropdown, as you hover over each item I would like an explanation of the selection to appear (like the ControlTipText).

An event must run somewhere in the background because the item hovered over changes colour (So that says to me if I can catch that event I must be able to add a label at the same time).

In the past when I have needed something like this I have used a label instead of a combobox and then made a frame appear (on click) with the correct number of labels needed (with a scroll) so that I could use the Mouse move event on the labels to change colour and add the ControlTipText (this gave the look of a combobox but with a lot more options) however due to the nature of the program I am making this is not possible, It needs to be a Combobox.

Please can anyone help??
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Code:
UserForm1.ComboBox1.ControlTipText = "Pick something"

Frequently it's done at design time in the Properties window rather than programaticaly.
 
Upvote 0
Hello mikerickson

Thanks for your reply,

That just changes the combobox ControlTipText.

One of my first problems was that when you click the drop down box of a combobox the ControlTipText is no longer visible.

But the major problem that I seek an answer for is how to catch the event when the hover over (mousemove) of individual items within the combobox occurs.

For instance if my combobox dropdown looked like
___________
|_________V|
choice1
choice2
choice3
choice4

as you hover over choice3 it will go blue (so an event must exist somewhere), I would then like to add to this event that a label (or something like the controltiptext) appear and give a breif discription of the choice (BEFORE it is selected) that way you can hover over each option to see if this is the one you want. Once selected a lot of stuff happens so I cant you the combobox change event.

Hope this has explained my question better

Cheers
GB
 
Upvote 0
Where is this combobox (userform or Sheet). Userform comboboxes have the MouseMove event that should do what you want. I believe that ActiveX comboboxes do also. ComboBoxes from the Forms menu don't trigger events.
 
Upvote 0
As mentioned, use the MouseMove event and calculate the row index of the hovered-over item from the Y position of the mouse:

Code:
Private Sub ComboBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Dim row As Integer
       
    If ComboBox1.TopIndex <> -1 Then
        'Show mouse co-ordinates - debugging only
        lblX.Caption = Format(X, "#.##")
        lblY.Caption = Format(Y, "#.##")
        
        row = Int(Y / (8 + 1.75))
        lblToolTip.Caption = "This is row index " & CStr(row)
    End If
    
End Sub
From there, you can use the 'row' variable as the index into an array or range to display the additional information about the highlighted item. I don't think you can update a tooltip though, only a label or text box or similar, as shown.

In the above code, 8 is the size of the ComboBox font and the + 1.75 is to account for the tiny gap between rows, giving 9.75 as the height of each highlighted row. The lblX and lblY labels are there to show the x,y co-ordinates of the mouse as you move it about.
 
Upvote 0
Hi Jaafar,

That is absolutely perfect!!!!!!!

This is by far the best thing i've seen in VBA for ages!!! Your a legend!!!

This should go in the Hall of Fme for cool answers (Im gonna Pm NateO)

Thnks Again

Paul
(GettingBetter)
 
Upvote 0
Hi Jaafar,

That is absolutely perfect!!!!!!!

This is by far the best thing i've seen in VBA for ages!!! Your a legend!!!

This should go in the Hall of Fme for cool answers (Im gonna Pm NateO)

Thnks Again

Paul
(GettingBetter)

Thanks for the compliment Paul and thanks for all your encouragement. I am glad i could be of help and believe me I learn more by trying to work out solutions for others than by asking questions. :)

Paul, i forgot to mention something, remember to save your work before editing the code to add your own tooltip message strings as the code uses "subclassing" and therefore any unhandled runtime error could potentially crash the entire XL application!

Regards.
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top