Syncronized scrolling of desktop listboxes

I’m using two side by side listboxes to display a simple list of routings from one channel (left listbox “From”) to another (Right Listbox, “To”). The left listbox doesn’t let you do anything, all of the items are fixed in position. In practice, the UI looks like this:

This allows you to drag around the rows in the “To” listbox to change the mappings.

I want to set up the left listbox to scroll in sync with the right listbox, if that list is long enough to trigger scrolling. If Row 5 on the “To” box is at the top, row 5 on the From box needs to be at the top of its listbox as well, so that you can visually see what maps and so it reflects the actual current mapping.

Plenty of old examples come up in google searches but they’re referencing deprecated (or possibly hallucinated) code.

What is the best way to do this? MouseWheel is the only event I can find that’s close, but there’s a good chance I will be putting this app on a Raspberry Pi with a touch screen, so there is no mousewheel, just a scrollbar. Is there really not an event for movement of a listbox’s vertical scrollbar?

Here’s an example of how to add a ScrollChanged event to a listbox by utilizing the PaintCellBackground event, since that is always called when the scroll position changes.

ScrollChangedListbox.xojo_binary_project.zip (6.3 KB)

You can add your own event definition for PaintCellBackground to the class and raise that at the end of the custom PaintCellBackground event in order to do your own drawing if needed.

2 Likes

If you’re definitely keeping it as two separate list boxes, then Jared’s solution is probably the one to go for.

Alternatively, I think it’s still possible to achieve this as a single list box with 2 columns, but would require some clever handling of the DragRow event to only allow dragging within the 2nd column and maybe even some overriding of cell painting to make it clear to the end user what is happening

Thanks. my use case is so simple that:

lbFroms.ScrollPosition = me.ScrollPosition

in the PaintCellBackground event on the one with the scrollbar is enough to trigger it and it seems to be keeping them in sync.

1 Like