Click here to Skip to main content
15,883,785 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi good people of codeproject, I have created a groupBox1 which contains 39 checkboxes which can be checked individually, and I have created a gropuBox2 which contains single check box called "Check All", What I want is when the "Check All" check box is checked all the 39 checkboxes will be selected and when the "Check All" is unchecked all 39 checkboxes will be unchecked also, Can someone please help? Thank you very much.
Posted
Updated 15-Oct-14 4:00am
v3

I think the best solution for this will be

C#
private void CheckUncheck()
       {
           foreach (CheckBox chk in groupBox1.Controls)
           {
               chk.Checked = chk.Checked == false;
           }
       }
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Oct-14 12:20pm    
Sure, a 5.
—SA
NaibedyaKar 15-Oct-14 12:28pm    
Happy that it helped you
Sergey Alexandrovich Kryukov 15-Oct-14 12:50pm    
Huh?
—SA
 
Share this answer
 
First solution :
VB
Private Sub cbxAll_CheckedChanged(sender As Object, e As System.EventArgs) Handles cbxAll.CheckedChanged                                                                      
    If cbxAll.Checked = True Then
        cbx01.Checked = True
        cbx02.Checked = True
        ' 3 .. 38
        cbx39.Checked = True
    Else
        cbx01.Checked = False
        cbx02.Checked = False
        ' 3 .. 38
        cbx39.Checked = False
    End If
End Sub


Second solution :
with the same event on checkbox(All) make a loop over all control of the form that match the name of the other 39 , if you name them in a proper way you can modify their property (.Checked = True/False).

Hope help
 
Share this answer
 
v2
Thank yoy very much for all your response, I've got the answer that I wanted by Bjorn-Roger Kringsja and it's:

VB
Private Sub CheckBoxAll_CheckedChanged(sender As Object, e As EventArgs) Handles CheckAll.CheckedChanged
    Array.ForEach(Me.GroupBox1.Controls.OfType(Of CheckBox).ToArray(), Sub(box As CheckBox) box.Checked = Me.CheckAll.Checked)
End Sub
 
Share this answer
 
v2

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