Locking scrollposition of 2 Listboxes together isn't working

I tried looking around for solutions on this issue, but didn’t find any. For desktop app development, there seems to be an issue with using the standard scrollposition method in both CellBackgroundPaint events, to keep the contents of both listboxes in sync. In the case of my issue, when I use the vertical scrollbars of either listbox, the opposite listbox content does not move.

I’m seeing this issue using 2019r3.1, but the same code running in 2019r1 works fine, and the contents of both listboxes stay in sync.

Here is a link to an example project that shows the issue.

I’m on Windows running Win10. Not sure if the behavior of the Listbox is the same on Mac, linux, Web.
Anyone have any workaround for this?

  • Karl

What are the odds, two paint related refresh issues on the same day.

This seems to be a side effect of anti paint recursion protection introduced in 2019r2 <https://xojo.com/issue/55615>

If you add this to your code it will force the other listbox to repaint, this would normally happen in the framework but its being prevented so you need to do it by hand.

Change your listbox1 code to this to see the temp fix

If Listbox2.ScrollPosition <> Me.ScrollPosition Then Listbox2.ScrollPosition = Me.ScrollPosition system.DebugLog(str(XojoVersion)) #If TargetWindows And XojoVersion > 2019.011 Const RDW_INVALIDATE = &h0001 Declare Function RedrawWindow Lib "User32" (hWnd As Integer, lprcUpdate As Integer, hrgnUpdate As Integer, flags As UInt32) As Int32 Call RedrawWindow(listbox2.handle, 0, 0, RDW_INVALIDATE) #EndIf End If