scroll event fires twice!! help.

P

Peter Row

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
 
P

Paul E Collins

Peter Row said:
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.
 
P

Peter Row

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 said:
Peter Row said:
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.
 
P

Paul E Collins

Peter Row said:
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.
 

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