Solved

Getting two listboxes to scroll together

Posted on 1998-06-29
5
309 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Try adding the List1.TopIndex = List2.TopIndex line to each event (or List2.TopIndex = List1.TopIndex )
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now