Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Other sample source codes
Synchronise the scrolling of two listboxes
Synchronise the scrolling of two listboxes 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 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
Privacy Policy
|
Link to Us
|
Links