?
Solved

Getting two listboxes to scroll together

Posted on 1998-06-29
5
Medium Priority
?
321 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

764 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