In this article I will explain with an example, how to check uncheck all (select unselect all) CheckBoxes in CheckedListBox in Windows Forms (WinForms) Application using C# and VB.Net.
The check uncheck all functionality will be done using an additional CheckBox that will act as Check All CheckBox for the CheckedListBox in Windows Forms (WinForms) Application using C# and VB.Net.
 
 
Form Design
The below Form consists of a CheckBox and a CheckedListBox control.
Check Uncheck all CheckBoxes in CheckedListBox in Windows Application using C# and VB.Net
 
 
Check Uncheck all CheckBoxes in CheckedListBox when Check All CheckBox is checked
When the Check All CheckBox is checked or unchecked, the Click event handler is executed.
A loop is executed over all the CheckBoxes of the CheckedListBox control and each CheckBox is checked or unchecked based on whether the Check All CheckBox is checked or unchecked using the SetItemChecked method.
C#
private void chkAll_Click(object sender, EventArgs e)
{
    for (int i = 0; i < chkFruits.Items.Count; i++)
    {
        chkFruits.SetItemChecked(i, chkAll.Checked);
    }
}
 
VB.Net
Private Sub chkAll_Click(sender As System.Object, e As System.EventArgs) Handles chkAll.Click
    For i As Integer = 0 To chkFruits.Items.Count - 1
        chkFruits.SetItemChecked(i, chkAll.Checked)
    Next
End Sub
 
 
Check Uncheck Check All CheckBox when other CheckBoxes in CheckedListBox are checked or unchecked
When any CheckBox of the CheckedListBox control is checked or unchecked, the SelectedIndexChanged event handler is executed.
A loop is executed over all the CheckBoxes of the CheckBoxList control and based on whether all the CheckBoxes of the CheckedListBox control are checked or unchecked, the Check All CheckBox is checked or unchecked.
C#
private void chkFruits_SelectedIndexChanged(object sender, EventArgs e)
{
    bool isAllChecked = true;
    for (int i = 0; i < chkFruits.Items.Count; i++)
    {
        if (!chkFruits.GetItemChecked(i))
        {
            isAllChecked = false;
            break;
        }
    }
 
    chkAll.Checked = isAllChecked;
}
 
VB.Net
Private Sub chkFruits_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles chkFruits.SelectedIndexChanged
    Dim isAllChecked As Boolean = True
    For i As Integer = 0 To chkFruits.Items.Count - 1
        If Not chkFruits.GetItemChecked(i) Then
            isAllChecked = False
            Exit For
        End If
    Next
 
    chkAll.Checked = isAllChecked
End Sub
 
 
Screenshot
Check Uncheck all CheckBoxes in CheckedListBox in Windows Application using C# and VB.Net
 
 
Downloads