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
Solved

Getting two listboxes to scroll together

Posted on 1998-06-29
5
318 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
message box in access 4 51
How to set the sa password in a vb6 code for sql connection 9 58
MsgBox 4 68
MS SQL Update query with connected table data 3 30
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

791 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