Click here to Skip to main content
15,881,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void chkMaster_CheckedChanged(object sender, EventArgs e)
{
bool chkMaster = (((System.Windows.Forms.CheckBox(sender)).Checked);
checkBoxCreateFolder.Checked = chkMaster;
checkBoxCredentials.Checked = chkMaster;
checkBoxIIS.Checked = chkMaster;
checkBoxNIComment.Checked = chkMaster;
checkBoxRemove.Checked = chkMaster;
checkBoxRemove.Checked = chkMaster;
checkBoxRemove.Checked = chkMaster;
checkBoxUncomment.Checked = chkMaster;
checkBoxUninstall.Checked = chkMaster;
checkBoxUpdateHelper.Checked = chkMaster;
Posted

You are almost there:
bool chkMaster = ((CheckBox)sender).Checked;
 
Share this answer
 
v2
Assuming that I wanted to check or un-check all the CheckBoxes in a container Control, like a Panel:
C#
private void SetAllCheckBoxesCheckState(Control container, bool isChecked)
{
    foreach (CheckBox cbx in container.Controls.OfType<CheckBox>())
    {
        cbx.Checked = isChecked;
    }
}

// sample use: SetAllCheckBoxesCheckState(panel1, true);
Note that using Controls.OfType<SomeControlType> only returns the top-level Controls in its target container whose Type matches (it is not recursive): if you have a CheckBox control in a panel within a Panel, .OfType will not find it.
 
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