Click here to Skip to main content
15,921,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use a CheckBox to select all the items in a CheckedListBox. How do I do that?
Posted

You mean if you check the single check box, all items in the CheckedListBox would be selected?

If that's the case I'm not sure if it's a good thing to do. The 'standard' way is to have a "Select all" button and in that button you would add all the items to ListBox.SelectedItems[^]
 
Share this answer
 
Add a CheckBox control above the CheckedListBox. You'll need to handle the new CheckBox's CheckChanged event. Note that the second parameter in the SetItemChecked command is a boolean that gets the Checked property of CheckBox1. Assuming you have a CheckBox named CheckBox1 and a CheckedListBox control named CheckedListBox1, this code will get it done:

VB
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    For l As Integer = 0 To CheckedListBox1.Items.Count - 1
      CheckedListBox1.SetItemChecked(l, CheckBox1.Checked)
    Next
  End Sub
 
Share this answer
 
your solution is given below
VB
Private Sub ChkALL_Click()
    Dim i

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

End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900