Combo Box Mouseover selection

R

Rudeseal

Hello,

I have a one column combobox on my form that I populate with the filenames
of photo's that are located in a directory on the harddrive.

What I am trying to do is when the dropdown list is open and you move the
mouse down the list, I want the text that is highlighted under the mouse to
be used to provide an image control with a "Preview" of the picture. This is
without clicking the mouse to select it.

I can do the same thing with using the mouse to open the dropdown list, then
use the up arrow and down arrow keys to cycle through the dropdown list which
then changes the text in the combobox's displayed text field and then fires
the "Change" event along with the keydown event. In the change event I have
code that uses the Combobox's text field to provide the image control the
name of the photo I want to preview.

I want to duplicate this action without having to use the keyboard itself,
simply use the mouse to highlight the record and see the preview image on the
form.

Moving the mouse up and down the dropdown list does not fire any events that
I can see, but it is actively highlighting each row of the dropdown list, so
I know the control knows which record is there so when a "Mouse-Down" event
happens or an "enter" is keyed, the text in the row is transferred to the
combobox text field.

I have tried everything I can to pull the text data of the row in the
dropdown list, but have failed. I know that when you are in the Mouseover
event, and you move the mouse from one highlighted record to another
highlighted record, the mousemove event is triggered only once and not
multiple times depending on the resolution of the mouse. In otherwords, when
the highlight changes from one record to another, not only does the highlight
move to the new record under the mouse, but mousemove is triggered.

Is there an API or something that can pull the record text from under the
mouse and duplicate what the up/down arrows on the keyboard are doing with
the combobox dropdown list?
 
D

Dale Fye

I think your challenge is determining what the ListIndex is of the item
displayed at the top of the combo boxes dropdown box.

It is relatively easy to use the mousemove event to identify which item is
being hovered over, but I have not been able to find a way to identify the
listindex of the top item displayed in the dropdown. I figured if anyone had
some code to do this, it would be Steve Lebans (www.lebans.com), but I could
not find it. To get the relative row, from the currently selected top, you
could do the following.

Private Sub Combo0_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)

Static VisibleIndex As Integer
Dim intVisibleIndex As Integer

intVisibleIndex = Int((Y - Me.Combo0.Height) / Me.Combo0.Height)
If intVisibleIndex <> VisibleIndex Then
VisibleIndex = intVisibleIndex
Debug.Print VisibleIndex
End If

End Sub
 
R

Rudeseal

Your right, that is an awful lot of work. I see that the code was written
for Access 2003, I am using Access 2007 on vista and Windows 7. Perhaps
there is a better and more simpler way?

Obviously the control know which row the mouse if over as it is able to
highlight each row and on a Mouse_Down event, write that date in to the Text
Box of the Combobox itself.

As for usefulness, it can be used to drill down through sucessive
combo-box's and only having to click on the row that you are looking for, or
if used with Date/time or other calander functions, can be used to "Pop-up"
detailed information on a particular date or time of a schedule, or as I am
using it, to preview pictures before selection the one I need updated in the
database. This can also be helpful for address information on huge databases
also. and if you are using a mobile device, much simpler to access data if
you can preview it on a pocket-pc instead of having to use arrows and button
pushes. Especially when MS releases the mobile version of office for Mobile
6.5 and 7. Anyhow I digress. If anyone has an updated solution and/or a
simpler one, I will be much appreciated
 
D

Dale Fye

I played around with this a bit, and can now call this subroutine from any
combo boxes mousedown event. Works pretty slick.

1. Put all of Steves code in a stand-alone code module
2. Put everything that was inside the MouseDown code into a subroutine in
that code module that accepted a combo box and the mouse pointers X and Y
values as parameters.

Public Sub ComboPosition(cbo as combobox, X as double, Y as Double)

3. Added a couple of lines of code to declare a form variable and set that
variable as the parent of the combo box passed as a parameter. Then changed
all of the references by doing a find/replace on (me. and frm.)

Dim frm as form
set frm = cbo.Parent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top