Discussion:
Keeping 2 listboxes in sync - VB6
(too old to reply)
Mojo
2009-07-05 13:07:06 UTC
Permalink
Hi All

Hope I explain this OK!

Basically I've got one listbox (incorporating checkboxes) that overlaps
another so that the following display is shown:

[ ] [ ] Cats
[ ] [ ] Dogs
[ ] [ ] Horses
[ ] [ ] Sheep
etc... etc..

The reason for this is so that the user can use the 1st column of checkboxes
to include particular people and the 2nd one to exclude them.

To try and keep both listboxes in sync when the user uses the top listbox's
scrollbar to go up and down I use the following code:

Private Sub lsbInitMenuList_Scroll(Index As Integer)
lsbInitMenuList(0).TopIndex = lsbInitMenuList(1).TopIndex
End Sub

Now I originally tested this on 3 x WinXP machines and it works fine, but
I've run it on a couple more XP machines and Vista machines and the
scrollbar scrolling makes the list go wappie!

The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync. Having
tried it on a Vista machine a few minutes go the listboxes do eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??

Thanks
Bob Butler
2009-07-05 13:22:54 UTC
Permalink
"Mojo" <***@dont.spam.com> wrote in message news:Odb9WGX$***@TK2MSFTNGP03.phx.gbl...
<cut>
Post by Mojo
The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync.
Having
tried it on a Vista machine a few minutes go the listboxes do eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??
If it were me I'd look at either using a grid control rather than the 2
listboxes or use a listbox that supports images (even a listview) and have 3
images (select, delete, no choice) and toggle through them as the user
clicks.
Mojo
2009-07-05 14:07:08 UTC
Permalink
Hi Bob

Thanks for your lightning reply.

Problem is I want to keep things tight so to complicate matters even more
this dual-listbox feature is actually a dropdown dual-listbox. Initial
display is a dropdown list with down arrow. User clicks the box or arrow to
reveal the dual-listbox.

With this I don't think the listview will work as I can only get one
checkbox per entry - can you get more?

I like the image combo option, but having had a little play you'd have to
keep clicking, scrolling and clicking again to change the state of an entry,
eg If I want to exclude the 16th entry I'd have to click on the combo to see
the list, scrolldown to the 16th entry, select it to change it to the
Include pic, combo disappears on the click so I'd have to click the combo
again, scroll down to the 16th entry, click on it again to change it to the
Exclude pic and then if I want it to go back to no selection I'd have to do
all of this process again. Am I way off the mark on how this would work?

Rgds

"Bob Butler" <***@nospam.ever> wrote in message news:OPZMePX$***@TK2MSFTNGP02.phx.gbl...

"Mojo" <***@dont.spam.com> wrote in message news:Odb9WGX$***@TK2MSFTNGP03.phx.gbl...
<cut>
Post by Mojo
The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync.
Having
tried it on a Vista machine a few minutes go the listboxes do eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??
If it were me I'd look at either using a grid control rather than the 2
listboxes or use a listbox that supports images (even a listview) and have 3
images (select, delete, no choice) and toggle through them as the user
clicks.
Bob Butler
2009-07-05 16:12:03 UTC
Permalink
Post by Mojo
Hi Bob
Thanks for your lightning reply.
Problem is I want to keep things tight so to complicate matters even more
this dual-listbox feature is actually a dropdown dual-listbox. Initial
display is a dropdown list with down arrow. User clicks the box or arrow to
reveal the dual-listbox.
That would have been useful to specify in the original post. I'd probably
consider replacing the combobox with a locked textbox or label or something
and when the user clicks on then I'd still display a grid or other control
which can then be hidden when the user makes their selection.
Post by Mojo
With this I don't think the listview will work as I can only get one
checkbox per entry - can you get more?
With a listview I was thinking of having one of 3 icons displayed depending
on the state of the entry. double-clicking the entry would rotate through
the available options and change the icon. That was before you mentioned
this being a drop-down list so to do that you'd probably need an alternate
way to close the display. A grid control makes more sense to me.

I'm sure others will have more options to suggest
Larry Serflaten
2009-07-05 17:58:07 UTC
Permalink
Post by Bob Butler
I'm sure others will have more options to suggest
I would have done a scrollable viewport setup (2 pictureboxes) and simply
draw the checkboxes and text. Its all just so many pixels on the screen,
what does the user know who draws them???

LFS
MikeD
2009-07-05 18:13:07 UTC
Permalink
Post by Mojo
Hi All
Hope I explain this OK!
Basically I've got one listbox (incorporating checkboxes) that overlaps
[ ] [ ] Cats
[ ] [ ] Dogs
[ ] [ ] Horses
[ ] [ ] Sheep
etc... etc..
The reason for this is so that the user can use the 1st column of checkboxes
to include particular people and the 2nd one to exclude them.
Maybe I'm just not understanding something, but why have 2 boxes at all?
Why won't just one work? Any that are checked are included. Any that are
not checked are excluded. I don't see why you need a box that's specific for
exclusion.
--
Mike
Dee Earley
2009-07-08 12:52:26 UTC
Permalink
Post by MikeD
Post by Mojo
Hi All
Hope I explain this OK!
Basically I've got one listbox (incorporating checkboxes) that overlaps
[ ] [ ] Cats
[ ] [ ] Dogs
[ ] [ ] Horses
[ ] [ ] Sheep
etc... etc..
The reason for this is so that the user can use the 1st column of checkboxes
to include particular people and the 2nd one to exclude them.
Maybe I'm just not understanding something, but why have 2 boxes at all?
Why won't just one work? Any that are checked are included. Any that are
not checked are excluded. I don't see why you need a box that's specific
for exclusion.
This has been discussed before, and what you propose is not the same thing.
Admittedly, with the sample values given, that is not clear... :)
--
Dee Earley (***@icode.co.uk)
i-Catcher Development Team

iCode Systems
Larry Serflaten
2009-07-05 19:15:31 UTC
Permalink
Post by Mojo
The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync. Having
tried it on a Vista machine a few minutes go the listboxes do eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??
With a minimal effort you can do the work yourself. To see what I mean, add
a Picturebox to a new form and place a VScroll bar inside the picturebox (so
the picturebox contains the scrollbar). Set the picturebox Appearance property
to 0 - Flat, then paste in the code below and see one possibility....

LFS

Option Explicit
Private Items, Values, TopIndex

Private Sub Form_Load()
Picture1.Move 300, 300, 2400, 2010
Picture1.AutoRedraw = True
Picture1.BackColor = vbWhite
Items = Array("Apple", "Banana", "Cherry", "Fig", "Grape", "Mango", _
"Pear", "Raspberry", "Strawberry", "Watermelon")
Values = Array(1, -1, 0, 0, 0, 0, 0, 0, 0, 0)
VScroll1.Min = 0
VScroll1.Max = 3
VScroll1.Value = 0
VScroll1.Move 2165, 0, 255, 1990
Picture1.Font.Size = 10
DrawList
End Sub

Private Sub DrawList()
Dim i, Y

Picture1.Cls
Picture1.Font.Name = "MS Sans Serif"
Picture1.Font.Bold = True
Picture1.Print " INC EXC ITEM"
Y = 240
For i = TopIndex To TopIndex + 6
LineItem i, Y
Y = Y + 240
Next
End Sub

Sub LineItem(idx, pos)
Debug.Print idx, pos, Items(idx)
Picture1.Line (120, pos)-Step(240, 240), vbBlack, B
Picture1.Line (660, pos)-Step(240, 240), vbBlack, B
Picture1.Font.Name = "MS Sans Serif"
Picture1.Font.Bold = False
Picture1.PSet (1110, pos), vbWhite
Picture1.Print Items(idx)
If Values(idx) <> 0 Then
Picture1.Font.Name = "Marlett"
Picture1.Font.Bold = False
Picture1.PSet (Values(idx) * -270 + 425, pos + 30)
Picture1.Print "b"
End If
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim yy
yy = Y \ 240
If yy > 0 And yy < 8 Then
OnClick X, yy - 1 + TopIndex
End If
End Sub

Sub OnClick(X, Y)
If X > 120 And X < 360 Then
If Values(Y) <= 0 Then
Values(Y) = 1
Else
Values(Y) = 0
End If
ElseIf X > 660 And X < 900 Then
If Values(Y) >= 0 Then
Values(Y) = -1
Else
Values(Y) = 0
End If
End If
DrawList
End Sub

Private Sub VScroll1_Change()
TopIndex = VScroll1
DrawList
End Sub

Private Sub VScroll1_GotFocus()
Picture1.SetFocus
End Sub

Private Sub VScroll1_Scroll()
TopIndex = VScroll1
DrawList
End Sub
Harald M. Genauck
2009-07-05 20:34:22 UTC
Permalink
Post by Mojo
Basically I've got one listbox (incorporating checkboxes) that
overlaps
[ ] [ ] Cats
[ ] [ ] Dogs
[ ] [ ] Horses
[ ] [ ] Sheep
etc... etc..
The reason for this is so that the user can use the 1st column of checkboxes
to include particular people and the 2nd one to exclude them.
To try and keep both listboxes in sync when the user uses the top listbox's
Private Sub lsbInitMenuList_Scroll(Index As Integer)
lsbInitMenuList(0).TopIndex = lsbInitMenuList(1).TopIndex
End Sub
Now I originally tested this on 3 x WinXP machines and it works fine, but
I've run it on a couple more XP machines and Vista machines and the
scrollbar scrolling makes the list go wappie!
The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync.
Having
tried it on a Vista machine a few minutes go the listboxes do
eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??
Maybe this might help you:
http://www.aboutvb.de/khw/artikel/khwcontrolsync.htm


Regards
Harald M. Genauck

"VISUAL STUDIO one" - http://www.visualstudio1.de
"ABOUT Visual Basic" - http://www.aboutvb.de
Estefania
2009-09-27 16:07:56 UTC
Permalink
Post by Mojo
Hi All
Hope I explain this OK!
Basically I've got one listbox (incorporating checkboxes) that overlaps
[ ] [ ] Cats
[ ] [ ] Dogs
[ ] [ ] Horses
[ ] [ ] Sheep
etc... etc..
The reason for this is so that the user can use the 1st column of checkboxes
to include particular people and the 2nd one to exclude them.
To try and keep both listboxes in sync when the user uses the top listbox's
Private Sub lsbInitMenuList_Scroll(Index As Integer)
lsbInitMenuList(0).TopIndex = lsbInitMenuList(1).TopIndex
End Sub
Now I originally tested this on 3 x WinXP machines and it works fine, but
I've run it on a couple more XP machines and Vista machines and the
scrollbar scrolling makes the list go wappie!
The underneath listbox doesn't seem to move as the top listbox starts to go
down and then the app seems to catch up to put them back into sync.
Having
tried it on a Vista machine a few minutes go the listboxes do eventually
line up again, but the wappie-ness of the entries go up-and-down and out of
sync looks pants and unprofessional. Is there anyway I can make this
smoother??
Thanks
Loading...