List box selection

  • Thread starter Thread starter Jacob
  • Start date Start date
J

Jacob

I have a list of objects in a list box that I need to select all at once. Is
there a way to do this?
 
Jacob-

here is my code for selecting/deselecting all list items

Dim n As Long

Select Case CheckBox.Value

Case 0:
'unselect all in list
With Listbox
For n = 0 To .ListCount - 1
.Selected(n) = False
Next
End With
Label.Caption = "Select all"
Case -1:
'select all in list
With ListBox
For n = 0 To .ListCount - 1
.Selected(n) = True
Next
End With
Label.Caption = "De-Select all"
End Select

HTH

Matt
 
Matt, that seems to work perfectly. However, when checked, only the last
record in the listbox is highlighted. Am I doing something else wrong?




Matt Williamson said:
Jacob-

Well.. for that code to work for you, you need a checkbox named checkbox, a
listbox named listbox and a label named label on a form. Otherwise, you'll
have to modify the code to fit your object names.

Put the code in the checkbox_click event in the forms module. Just double
click the checkbox in design mode and goto the event tab, select [Event
Procedure] and click the [...] box to bring up the code window.

HTH

Matt

Jacob said:
Matt, which property should I place this in? I tried it in the ONCLICK and
that did not seem to work.
 
Jacob-

You have to set the Multiselect property of the listbox to simple or
extended.

HTH

Matt

Jacob said:
Matt, that seems to work perfectly. However, when checked, only the last
record in the listbox is highlighted. Am I doing something else wrong?




Matt Williamson said:
Jacob-

Well.. for that code to work for you, you need a checkbox named
checkbox,
a
listbox named listbox and a label named label on a form. Otherwise, you'll
have to modify the code to fit your object names.

Put the code in the checkbox_click event in the forms module. Just double
click the checkbox in design mode and goto the event tab, select [Event
Procedure] and click the [...] box to bring up the code window.

HTH

Matt

Jacob said:
Matt, which property should I place this in? I tried it in the ONCLICK and
that did not seem to work.


Jacob-

here is my code for selecting/deselecting all list items

Dim n As Long

Select Case CheckBox.Value

Case 0:
'unselect all in list
With Listbox
For n = 0 To .ListCount - 1
.Selected(n) = False
Next
End With
Label.Caption = "Select all"
Case -1:
'select all in list
With ListBox
For n = 0 To .ListCount - 1
.Selected(n) = True
Next
End With
Label.Caption = "De-Select all"
End Select

HTH

Matt

I have a list of objects in a list box that I need to select all at
once.
Is
there a way to do this?
 
Back
Top