Hello All,

Hope you are doing great.

I need your help to make two WinForms listviews synchronized on both Vertical and Horizontal scrolls (using the scrolls or mouse middle wheele) using VB.NET (2013).

I've followed kleinma perfect example there http://www.vbforums.com/showthread.p...-of-2-listview

But still I am unable to make what I want.


Public Class ffListView
Inherits ListView
'Protected Overrides Sub WndProc(ByRef m As Message)
' If m.Msg = &H203 Then m.Msg = &H201
' MyBase.WndProc(m)
'End Sub

'SCROLL CONSTANTS
Private Const SBM_SETSCROLLINFO As Integer = &HE9
Private Const WM_HSCROLL As Integer = &H115
Private Const WM_VSCROLL As Integer = &H114

'CUSTOM EVENT
Public Event Scroll(ByVal sender As Object, ByVal e As EventArgs)

Protected Sub OnScroll()
RaiseEvent Scroll(Me, EventArgs.Empty)
End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_HSCROLL OrElse m.Msg = WM_VSCROLL OrElse m.Msg = SBM_SETSCROLLINFO Then
OnScroll()
End If
End Sub

End Class


The above custom Listview is working perfectly .. but when I use the mouse wheel to scroll, there is no vertical synchronization >> problem ONE

And I need to synchronize the horizontal scrolls as well .. The main is lstvwOutput and the follower is lstvwOriginal >> problem TWO


Private Const WM_HSCROLL As Integer = &H114
Private Const WM_VSCROLL As Integer = &H115

Private Const SBS_HORZ As Integer = 0
Private Const SBS_VERT As Integer = 1

Private Declare Function GetScrollPos Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
Private Declare Function SetScrollPos Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer
Private Declare Function PostMessageA Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean
Private Sub scrollControl(ByVal hWnd As IntPtr, ByVal Amount As Integer)
If SetScrollPos(hWnd, SBS_HORZ, Amount, True) <> -1 Then
PostMessageA(hWnd, WM_HSCROLL, &H10000 * Amount, 50)
Else
'MsgBox("Can't set info (Err: " & GetLastWin32Error() & ")")
End If

End Sub


Private Sub lstvwOutput_Scroll(sender As Object, e As EventArgs) Handles lstvwOutput.Scroll
lstvwOriginal.TopItem = lstvwOriginal.Items(lstvwOutput.TopItem.Index)

scrollControl(lstvwOriginal.Handle, GetScrollPos(lstvwOutput.Handle, SBS_HORZ))
lstvwOriginal.Invalidate()
End Sub


Could you kindly help me on these two problems?


Thanks,
Moatassem