Home All Groups Group Topic Archive Search About

Best method to have 2 checkboxes for 1 item

Author
5 Jul 2009 2:36 PM
Mojo
Hi All

I've used a combination of a dropdown list and 2 x listboxes overlapped to
give the user the ability to click on a drop-down and then scroll down a
list to 'Include' or 'Exclude' an item depending on which checkbox they
click, eg:

Inc  Exc
[x]    [ ]     Computer Club
[ ]     [ ]     Comes from overseas
[ ]    [x]     Like Milk
[ ]    [x]     Part time job
etc... etc...

This frankenstein control worked fine until I noticed that the 2 listboxes
can't be kept in sync when scrolling so the checkboxes look like they are
going wappie when the user uses the scrollbar.

I'm desperately trying to resolve this, but I was wondering if there is a
better control to get this effect - any ideas?

Rgds

Author
5 Jul 2009 4:06 PM
Bob Butler
"Mojo" <please@dont.spam.com> wrote in message
news:%23PDfO4X$JHA.5092@TK2MSFTNGP03.phx.gbl...
> Hi All

Please don't post the same question multiple times
Author
5 Jul 2009 5:58 PM
Mike Williams
"Mojo" <please@dont.spam.com> wrote in message
news:%23PDfO4X$JHA.5092@TK2MSFTNGP03.phx.gbl...

> Hi All. I've used a combination of a dropdown list
> and 2 x listboxes overlapped to give the user the
> ability to . . .

You really are going to have to stop posting to all those groups, some of
them separately, and also stop posting thread after thread on the same
subject. Just post one thread and have a bit of patience! For what it's
worth I posted a response to one of your threads in one of the groups (can't
remember which thread or group now!) suggesting that you might like to use a
scrollable PictureBox on the grounds that you can customise such an
arrangement to work in just about any way you wish. Here, again, is my
posted suggestion just in case you can't find it amongst all those groups
and all those threads :-)  It's just a "bare bones" test at the moment, but
it can of course be customised in all sorts of different ways. To try it out
start a new VB project and place two Picture Boxes, two Check Boxes, one
Label Control and one Vertical ScrollBar on your Form. Make sure that in the
IDE at design time you set the Index
property of the two Check Boxes and the Label Control to zero (you need to
select each of them and actually enter 0 into the Index
property in the Properties window). Then paste in the following code and
give it a run:

Mike

Option Explicit

Private Sub Form_Load()
Dim n As Long
Dim s1() As String
ReDim s1(0 To 49)
s1(0) = "Computer Club"
s1(1) = "Comes from overseas"
s1(2) = "Likes milk"
s1(3) = "Has part time job"
' etc, etc
' (it might be best to actually
' load these from a data file)
Me.ScaleMode = vbPixels
Picture1.ScaleMode = vbPixels
Picture2.ScaleMode = vbPixels
Picture1.Move 20, 20, 180, 250
Picture2.BorderStyle = vbBSNone
Picture2.BackColor = vbWhite
Picture2.Width = Picture1.ScaleWidth
Set Picture2.Container = Picture1
Picture2.Move 0, 0
VScroll1.Move Picture1.Left + Picture1.Width, Picture1.Top, _
    VScroll1.Width, Picture1.Height
VScroll1.TabStop = False
Set Check1(0).Container = Picture2
Check1(0).BackColor = vbWhite
Check1(0).Caption = ""
Check1(0).Move 4, 0, 20, 20
Set Check2(0).Container = Picture2
Check2(0).BackColor = vbWhite
Check2(0).Caption = ""
Check2(0).Move 24, 0, 20, 20
Set Label1(0).Container = Picture2
Label1(0).BackStyle = vbTransparent
Label1(0).Move 44, 2, Picture2.Width - 44, 20
Label1(0).Caption = s1(0)
For n = 1 To 49 ' a further 49 items
  Load Check1(n)
  Check1(n).Move 4, 20 * n, 20, 20
  Check1(n).Visible = True
  Load Check2(n)
  Check2(n).Move 24, 20 * n, 20, 20
  Check2(n).Visible = True
  Load Label1(n)
  Label1(n).Move 44, 2 + 20 * n, Picture2.Width - 44, 20
  If s1(n) = "" Then
    Label1(n).Caption = "This is item number " & Format(n + 1)
  Else
    Label1(n).Caption = s1(n)
  End If
  Label1(n).Visible = True
Next n
Picture2.Height = n * 20
VScroll1.Min = 0
VScroll1.Max = Picture2.Height - Picture1.ScaleHeight
VScroll1.Value = 0
VScroll1.SmallChange = 20 ' pixels per click
VScroll1.LargeChange = 100
End Sub

Private Sub VScroll1_Change()
Picture2.Top = (-VScroll1.Value)
End Sub

Private Sub VScroll1_Scroll()
Picture2.Top = (-VScroll1.Value)
End Sub
Author
5 Jul 2009 6:42 PM
mayayana
>
> I've used a combination of a dropdown list and 2 x listboxes overlapped to
> give the user the ability to click on a drop-down and then scroll down a
> list to 'Include' or 'Exclude' an item depending on which checkbox they
> click, eg:
>
>  Inc  Exc
> [x]    [ ]     Computer Club
> [ ]     [ ]     Comes from overseas
> [ ]    [x]     Like Milk
> [ ]    [x]     Part time job
> etc... etc...

  Since Include is the opposite of Exclude, why
can't you just use one listbox with a check for
Include? (Checked means include, unchecked
means exclude.)
Author
5 Jul 2009 7:42 PM
Larry Serflaten
"mayayana" <mayaXXy***@rcXXn.com> wrote

>   Since Include is the opposite of Exclude, why
> can't you just use one listbox with a check for
> Include? (Checked means include, unchecked
> means exclude.)

One possible example:

Search all newsgroups for the words 'Listbox' and 'Checkbox' but exclude those
messages that include the word 'Net'.

Include and exclude are both used....

   ;-)
LFS
Author
6 Jul 2009 10:57 AM
duke
Show quote Hide quote
On Jul 5, 8:36 am, "Mojo" <ple...@dont.spam.com> wrote:
> Hi All
>
> I've used a combination of a dropdown list and 2 x listboxes overlapped to
> give the user the ability to click on a drop-down and then scroll down a
> list to 'Include' or 'Exclude' an item depending on which checkbox they
> click, eg:
>
>  Inc  Exc
> [x]    [ ]     Computer Club
> [ ]     [ ]     Comes from overseas
> [ ]    [x]     Like Milk
> [ ]    [x]     Part time job
> etc... etc...
>
> This frankenstein control worked fine until I noticed that the 2 listboxes
> can't be kept in sync when scrolling so the checkboxes look like they are
> going wappie when the user uses the scrollbar.
>
> I'm desperately trying to resolve this, but I was wondering if there is a
> better control to get this effect - any ideas?
>
> Rgds

Maybe this will give you a different direction to consider:

The Form_Load code is there just to load the list box for my test
purposes and would have to be replaced with your specific code for
loading the listbox with the appropriate information.

Good Luck


Private Sub Form_Load()
  For idx = 1 To 20
    List1.AddItem ("[   ] - [   ]  This is item " & idx)
  Next

End Sub

Private Sub List1_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
  Select Case X
    Case 100 To 210
      If InStr(3, List1.List(List1.ListIndex), "X") > 0 Then
        List1.List(List1.ListIndex) = "[   ]" & Mid(List1.List
(List1.ListIndex), 6)
      Else
        List1.List(List1.ListIndex) = "[ X ]" & Mid(List1.List
(List1.ListIndex), 6)
      End If
    Case 420 To 530
      If InStr(11, List1.List(List1.ListIndex), "X") > 0 Then
        List1.List(List1.ListIndex) = _
          Mid(List1.List(List1.ListIndex), 1, 8) & "[   ]" & Mid
(List1.List(List1.ListIndex), 14)
      Else
        List1.List(List1.ListIndex) = _
          Mid(List1.List(List1.ListIndex), 1, 8) & "[ X ]" & Mid
(List1.List(List1.ListIndex), 14)
      End If
  End Select

End Sub