Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting two listboxes to scroll together

Posted on 1998-06-29
5
Medium Priority
?
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
royster earned 90 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

609 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