ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Detecting scrolling in listboxes (https://www.excelbanter.com/excel-programming/371271-detecting-scrolling-listboxes.html)

mrt

Detecting scrolling in listboxes
 
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


ChasAA

Detecting scrolling in listboxes
 
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

"MrT" wrote:

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


NickHK

Detecting scrolling in listboxes
 
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

"MrT" wrote in message
...
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




mrt

Detecting scrolling in listboxes
 
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


NickHK

Detecting scrolling in listboxes
 
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

"MrT" wrote in message
...
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




NickHK

Detecting scrolling in listboxes
 
I mean "react to the ListBox_Change event when the user has selected their
choice"

NickHK

"MrT" wrote in message
...
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




mrt

Detecting scrolling in listboxes
 
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

"NickHK" wrote:

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

NickHK

"MrT" wrote in message
...
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





NickHK

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

NickHK

"MrT" wrote in message
...
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

"NickHK" wrote:

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

their
choice"

NickHK

"MrT" wrote in message
...
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







mrt

Detecting scrolling in listboxes
 
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



"MrT" wrote in message
...
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

"NickHK" wrote:

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

their
choice"

NickHK

"MrT" wrote in message
...
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








NickHK

Detecting scrolling in listboxes
 
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

"MrT" wrote in message
...
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



"MrT" wrote in message
...
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

"NickHK" wrote:

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

their
choice"

NickHK

"MrT" wrote in message
...
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










Dave Peterson

Detecting scrolling in listboxes
 
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?

MrT wrote:

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


"MrT" wrote in message
...
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

"NickHK" wrote:

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

their
choice"

NickHK

"MrT" wrote in message
...
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








--

Dave Peterson

mrt

Detecting scrolling in listboxes
 
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




NickHK

Detecting scrolling in listboxes
 
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


"MrT" wrote in message
...
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






Dave Peterson

Detecting scrolling in listboxes
 
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.


MrT wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 01:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com