By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,205 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,205 IT Pros & Developers. It's quick & easy.

scroll event fires twice!! help.

P: n/a
Hi,

I have created a user control consisting of a textbox and a separate
vertical scroll bar.

The textbox is filled with data. However there could be lots of data
so I only fill the textbox with enough to fill the space visible without
scrolling. Having set the min and max values of my separate vertical
scrollbar I use that to scroll the data. So for example the textbox
could be displaying 50 lines of data but in actual fact there is 1000
lines of data. So my scrollbar will have min = 0, max = 1000.

Now the thing I want to do is check if the user only scrolled 1 line.
So I add a handler to the scroll event of my vertical scroll bar.
I then click the down arrow on the scroll bar. BUT this causes the
scroll event to be fired twice!

The first time it fires the args of the event tell me the ScrollEventType
was SmallIncrement (which is what I expect and want) and the
difference between the current value and the new value is 1
(which is what I expect and want given my vsb's properties).

However it then immediately gets fired again, but this time the
ScrollEventType is EndScroll and the current and new values are
the same.

Anybody have any ideas why the event is being fired twice?

Regards,
Peter
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Peter Row" <fuck.off@bastard_spammers.com> wrote:
The first time it fires the args of the event tell me the
ScrollEventType was SmallIncrement (which is what
I expect and want) [...] However it then immediately
gets fired again, but this time the ScrollEventType is
EndScroll and the current and new values are
the same.


Well, this sounds like correct behaviour. If you don't want to deal
with event types other than SmallIncrement, write an if statement to
ignore them in your event handler.

P.
Nov 16 '05 #2

P: n/a
Hi,

Can you or perhaps someone else please explain why this is correct
behaviour?

If I click the down arrow of a vertical scroll bar once I would expect
the scroll event to fire once not twice. Similarly if I clicked on the bar
to get a LargeIncrement I would still expect the scroll event to fire
once.

To get around this double firing I simply check if the current and new
value are different, if they are then this means it is the first time firing
and so I can store the ScrollEventType for use later. The second time
it fires for no apparent reason, the current and new values are the same
so I ignore it.

Thanks for responding,
Peter
"Paul E Collins" <fi******************@CL4.org> wrote in message
news:ch**********@titan.btinternet.com...
"Peter Row" <fuck.off@bastard_spammers.com> wrote:
The first time it fires the args of the event tell me the
ScrollEventType was SmallIncrement (which is what
I expect and want) [...] However it then immediately
gets fired again, but this time the ScrollEventType is
EndScroll and the current and new values are
the same.


Well, this sounds like correct behaviour. If you don't want to deal
with event types other than SmallIncrement, write an if statement to
ignore them in your event handler.

P.

Nov 16 '05 #3

P: n/a
"Peter Row" <fuck.off@bastard_spammers.com> wrote:
Can you or perhaps someone else please explain
why this is correct behaviour?
If I click the down arrow of a vertical scroll bar
once I would expect the scroll event to fire once
not twice.


I agree that it seems to be rather poor design. You'd expect
SmallIncrement, LargeIncrement, and EndScroll to be distinct events,
but instead there is a single Scroll event whose parameter
(ScrollEventType) indicates what "event" is really happening.

P.
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.