Synchronize two Listviews scroll
I have two Listviews side-by-side and I want their scrolling behavior to be synchronized. I.E. When the user drags the vertical scroll bar up or down on one list view, I would like the other listview to do the same.
I have already hooked the two listviews and trapped the WM_VSCROLL messages, which are fine for when the user clicks the "Scroll Up" and "Scroll Down" arrows on the scroll bar. But what messages can I trap to detect when the user drags the scrollbar with the mouse?
Thanks
Re: Synchronize two Listviews scroll
Hey,
Did you find a solution for your issue?
I know it is almost 12 years ago! :)
Re: Synchronize two Listviews scroll
Seems you need to check the LOWORD of wParam when receiving a Scroll message.
Quick test in VB.Net,....
Code:
Public Class ListViewEx
Inherits ListView
Private Const SB_THUMBTRACK As Int32 = 5
Private Const SB_ENDSCROLL As Int32 = 8
Private Const WM_VSCROLL As Int32 = &H115
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_VSCROLL
' see https://msdn.microsoft.com/en-us/library/windows/desktop/bb787577(v=vs.85).aspx
'
' wParam
' The LOWORD specifies a scroll bar value that indicates the user's scrolling request.
'
' get LOWORD from wParam
Dim lw = LOWORD(m.WParam)
' show result
Select Case lw
Case SB_THUMBTRACK
Debug.WriteLine("The user is dragging the scroll box. ")
Case SB_ENDSCROLL
Debug.WriteLine("Ends scroll.")
End Select
End Select
MyBase.WndProc(m)
End Sub
' Converted to VB from NativeMethods.cs,
' http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/NativeMethods.cs,e1ab28ba69954959
Public Shared Function LOWORD(n As Integer) As Integer
Return n And &HFFFF
End Function
Public Shared Function LOWORD(n As IntPtr) As Integer
Return LOWORD(CInt(CLng(n)))
End Function
End Class