Solved

Getting two listboxes to scroll together

Posted on 1998-06-29
5
313 Views
Last Modified: 2012-06-21
Has anyone any ideas on how to get two listboxes on a form to scroll together - by that I mean when scrolling down one list box then the other one scrolls also. Similarly when scrolling the second one then the first one should also scroll. Thanks in advance.
0
Comment
Question by:dgb001
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
royster earned 30 total points
ID: 1464547
Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List1_Scroll()
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List2_KeyUp(KeyCode As Integer, Shift As Integer)
List1.ListIndex = List2.ListIndex
End Sub

Private Sub List2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.ListIndex = List2.ListIndex
End Sub

Private Sub List2_Scroll()
List1.ListIndex = List2.ListIndex
End Sub

0
 
LVL 1

Expert Comment

by:royster
ID: 1464548
This will work better:
Private Sub Form_Load()
List1.ListIndex = 0
List2.ListIndex = 0
End Sub

Private Sub List1_KeyUp(KeyCode As Integer, Shift As Integer)
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List2.ListIndex = List1.ListIndex
End Sub

Private Sub List1_Scroll()
List2.TopIndex = List1.TopIndex
End Sub

Private Sub List2_KeyUp(KeyCode As Integer, Shift As Integer)
List1.ListIndex = List2.ListIndex
End Sub

Private Sub List2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
List1.ListIndex = List2.ListIndex
End Sub

Private Sub List2_Scroll()
List1.TopIndex = List2.TopIndex
End Sub

0
 
LVL 1

Author Comment

by:dgb001
ID: 1464549
I haven't tried it yet Royster, but I'll give it a go shortly - thanks, I'll let you know.

0
 
LVL 1

Author Comment

by:dgb001
ID: 1464550
Thanks Royster, that works nicely (the second one). The only thing I did notice though is that if integral height is set to false, then although the code still works fine, sometimes it can give the "appearance" that the selected items in each list are not in line with each other, even if the font sizes and lists are the same size. But thanks, that's very useful.

Dave
0
 
LVL 1

Expert Comment

by:royster
ID: 1464551
Try adding the List1.TopIndex = List2.TopIndex line to each event (or List2.TopIndex = List1.TopIndex )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
DIR issue 7 51
Paint/Redraw window while dragging 16 68
Updates not working for MS Windows 7 12 154
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now