VB and VBA Users Source Code: Synchronise the scrolling of two listboxes
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Synchronise the scrolling of two listboxes
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, February 06, 2001
Hits:
1088
Category:
Windows API
Article:
To synchronise the scrolling of two listboxes use the following routines: Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 'Purpose : Synchronises the scrolling of two listboxes 'Inputs : lhwndMasterListbox The handle to the listbox with the focus. ' lhwndSlaveListbox The handle to the listbox which is to ' follow the scrolling of the master listbox. 'Outputs : On successful returns zero 'Author : Andrew Baker 'Date : 31/01/2001 14:35 'Notes : 'Revisions : Function ListboxSynchronise(lhwndMasterListbox As Long, lhwndSlaveListbox As Long) As Long Const LB_GETTOPINDEX = &H18E, LB_SETTOPINDEX = &H197 ListboxSynchronise = SendMessage(lhwndSlaveListbox, LB_SETTOPINDEX, SendMessage(lhwndMasterListbox, LB_GETTOPINDEX, 0&, 0&), 0&) End Function 'Demonstration routines. 'Place inside a form containing two listboxes. Private Sub List1_Scroll() ListboxSynchronise Me.List1.hwnd, Me.List2.hwnd End Sub Private Sub List2_Scroll() ListboxSynchronise Me.List2.hwnd, Me.List1.hwnd End Sub Private Sub Form_Load() Dim lThisRow As Long For lThisRow = lThisRow To 50 List1.AddItem "Item " & CStr(lThisRow) List2.AddItem "Item " & CStr(lThisRow) Next End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder