Listbox Scroll Event?

Hey guys,

How would one go about detecting when a listbox is scrolled? I don’t see a scroll event or similar. You can get the scroll position but that’s not really useful when you are trying to detect the scroll happening…

Ideas?

Just looked in some older code I had. Looks like there I handled things in the CellBackgroundPaint event - I would check the scroll position there. Bummer there’s not a real event…

Feature request?

Yeah, I think that’s a good idea… :slight_smile:

<https://xojo.com/issue/47752>

Off the top of my head:

1)Subclass list box
2)Add LastScrollPosition private integer property

3)Define New Event Scrolled(LastPosition as Integer)

4)Duplicate cellbackgroundPaint event

5)In the the Existing CellBackgroundpaint:

If LastScrollPosition <> ScrollPosition Then RaiseEvent Scrolled(LastScrollPosition) LastScrollPosition = ScrollPosition End If RaiseEvent CellBackgroundPaint(with the params)

Now you have an event that fires after the listbox scrolls
HTH
Karen

Yeah, that’s what I have. I would just be nice to have an actual event instead of triggering that code any time a cell gets painted…

It introduces very little overhead.

  • karen

But you are not triggering it EVERY time… the cells get painted constantly… but this event as Karen described it only triggers when the cell has moved.

Similar code could be used for horizontal scrolling (which I use to synch my CustomListbox header)

Is there a way to add an Event Definition to a subclass that can be called by that same subclass?
Seems when I create an Event Definition (Scrolled), an event handler for that event can only be added to an instance of the subclass.

i.e. I want to handle the event within the subclass, not the instance of that subclass.

[quote=466075:@Andy Broughton]Is there a way to add an Event Definition to a subclass that can be called by that same subclass?
Seems when I create an Event Definition (Scrolled), an event handler for that event can only be added to an instance of the subclass.
[/quote]
this is correct

if you want to handle the event IN that instance then just don’t raise an event and call a method in that instance

Gotcha. Thanks, Norman!