Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checkbox to select all data in a listbox 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
0
0
US
I have put a checkbox on top of a listbox with rows of data in it. What I want to happen is when I check the checkbox all the rows in the listbox get selected. Right now I get no errors but nothing happens.
names: listbox - lstARlstbox checkbox - chkPosFilter
Any help would be appreciated
This is the current code:
[] code
Private Sub chkPOSFilter_Click()
Dim i

For i = 0 To lstARLstbox.ListCount - 1
lstARLstbox.Selected(i) = ChkALL
Next i

End Sub

 
What is ChkALL ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
That was my problem I needed to rename where my data was coming from.
Thanks
 
Hi

Ensure that the property 'MultiSelect' is set to 'Simple' or 'Extended' on the listbox and try the following code in your 'OnClick' event of the checkbox

Dim i
If chkPOSFilter.Value = True Then
For i = 0 To lstARlstbox.ListCount - 1
lstARlstbox.Selected(i) = True
Next i
Else
For i = 0 To lstARlstbox.ListCount - 1
lstARlstbox.Selected(i) = False
Next i
End If

Hope this helps


Sometimes if you want to put a nail in a piece of wood, you just gotta hit it with a hammer!!
 
How are ya rekrabnai . . .

Just a little crunching and I get:
Code:
[blue]   Dim lbx As ListBox, i As Integer
   
   Set lbx = Me.lstARlstbox
   
   For i = 0 To lbx.ListCount - 1
      lbx.Selected(i) = (chkPOSFilter = True)
   Next[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Even simpler:
Code:
For i = 0 To lbx.ListCount - 1
  lbx.Selected(i) = chkPOSFilter
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top