Detecting scrolling in listboxes

G

Guest

Hi There,

I want to synchronize two listboxes (I mean having the same topindex for
both) on the same form, and unfortunatelly I cannot find any event related to
the scrolling, and the other control events are ineffective when the mouse is
overthe scrollbar.

Has anyone met that problem and found a solution?

Thanks,

MrT
 
G

Guest

Hello,
I understand that are looking for a scroll related event but would you mind
saying a bit more of what you want to do or even post an example of code.

Chas
 
N

NickHK

As the list box does not expose the Scroll event, the only way would be to
subclass the control and intercept that message. It appears to be class
called "F3 Server 03a80000".
I find Excel does not act well with subclassing, so unless you really need
to go in that direction, change you approach.

Can you not react to the ListBox_Change events ?
Otherwise you can fake it with you own scroll bar on frame over the right
edge of the list box.
Then do what you need in the scroll bar's Scroll/Change event.

NickHK
 
G

Guest

Can you not react to the ListBox_Change events ?

No, none of the event reacts when you scroll down, as amazing as it might
seem. Event the Enter event does not react when you enter via the scroll bar.
It looks like the scrollbar is anothercontrol separate from the listbox.
Then do what you need in the scroll bar's Scroll/Change event.

That's what I've done so far, but it is quite complex to adapt the scrollbar
to the listbox.

MrT
 
N

NickHK

You are talking about a combo box, not a list box ?
If a combo box, then yes, the list part is a separate control to the edit
part ; the combo box combines them.

What are trying to achieve ?

NickHK
 
N

NickHK

I mean "react to the ListBox_Change event when the user has selected their
choice"

NickHK
 
G

Guest

Nick,

Just have a try. Create a ListBox in a form, enter enough rows via the List
method so that you have a vertical scrollbar. Then try to detect when you
scroll. I can't.

MrT
 
G

Guest

I know you don't get the Scroll event .
My question was why do you need to ?

Because I want to change the TopIndex of another listboxin the same form so
that they are synchronized.

MrT
 
N

NickHK

With ListBox1 in a frame and pushed to the right to hide it's scroll bar and
Scrollbar1 aligned to fake its scroll bar :

Private Sub ListBox1_Change()
ListBox2.TopIndex = ListBox1.TopIndex
ScrollBar1.Value = ListBox1.TopIndex
End Sub

Private Sub ListBox1_Click()
ListBox2.TopIndex = ListBox1.TopIndex
ScrollBar1.Value = ListBox1.TopIndex
End Sub

Private Sub ScrollBar1_Change()
ListBox1.TopIndex = ScrollBar1.Value
ListBox2.TopIndex = ListBox1.TopIndex
End Sub

Private Sub ScrollBar1_Scroll()
ListBox1.TopIndex = ScrollBar1.Value
ListBox2.TopIndex = ListBox1.TopIndex
End Sub

Private Sub UserForm_Initialize()
Dim i As Long

For i = 1 To 25
ListBox1.AddItem "Item " & i
ListBox2.AddItem "Item " & i
Next

With ScrollBar1
.Min = 0
.Max = ListBox1.ListCount - 1
End With

End Sub

NickHK
 
D

Dave Peterson

Maybe you could build your own listbox using textboxes and scrollbars???

Or maybe you can find a different control (google???) that you can purchase(?),
use, and distribute???

Or maybe you could use a multicolumn listbox so you don't need to use a second
listbox?
 
G

Guest

Dave,

Thanks for your reply. I used another solution that is intermediate, and
fine although not totally satisfactory. The listboxes are only synchronized
when the user moves the mouse over one of the two listboxes.
Maybe you could build your own listbox using textboxes and scrollbars???

Sure, but that's heavy, and I wonder why the developers of Excel did not
create an event related to scrolling in listboxes and textboxes.
Or maybe you can find a different control (google???) that you can purchase(?),
use, and distribute???

I didn't know that controls from third parties are available. Do you know
some?
Or maybe you could use a multicolumn listbox so you don't need to use a second
listbox?

I'm using 2 listboxes, because I want to have 2 checkboxes for each item
(one listbox is overlapping on the other).

Cheers,

MrT
 
N

NickHK

There are many aspects that could have been exposed at all levels for
controls, components and applications compared to what is actually happening
in Windows.
It's up to you to deal with those limitations or expand on them yourself.

Yes, you can use (most) ActiveX controls.

As a quick example, I've made a custom control that exposes the Scroll event
with an .Add method and Let/Get .TopIndex property. That's all at the
moment.
Let me know your email and I'll send it to you, to see if it really does
make that much difference .

NickHK
 
D

Dave Peterson

I wouldn't do any of that build from scratch stuff!

The only one I know of is from Nick! And I found out about it today.
 

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