Link two listboxes together

G

greenfalcon

I have a quick question. I have a form with lets say 2 separet
listboxes on it. A lstBox1 and lstBox2. Now what i need these to do i
if you scroll down with list box1, listbox2 moves scrolls down as well
Really what i am trying to do is the two listboxes have data in the
that needs to relate to the information in the other one, I cant hav
one list box move because then all the data is in the wrong place...
for example

This is how its supposed to look

lstBox1 lstBox2
a a
b b
c c
d d

i cant have this happen, when scroll box1 is scrolled the info in box
does not move.

lstBox1 lstBox2

b a
c b
d c


Hopefully this is clear enough.

Thanks for your hel
 
D

Dave Peterson

I don't know if it's possible, but why not just have multiple columns in one
listbox and make the listbox wide enough to show both. It seems like a much
easier solution.

But you could sync the listboxes after you leave one of them:

Option Explicit
Private Sub ListBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.ListBox1.TopIndex = Me.ListBox2.TopIndex
End Sub
Private Sub ListBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Me.ListBox2.TopIndex = Me.ListBox1.TopIndex
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
With Me.ListBox1
.IntegralHeight = True
For iCtr = 1 To 20
.AddItem "asdf" & iCtr
Next iCtr
End With
With Me.ListBox2
.IntegralHeight = True
.Top = Me.ListBox1.Top
.Height = Me.ListBox1.Height
For iCtr = 1 To 20
.AddItem "qwer" & iCtr
Next iCtr
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top