I am trying to write a code which will uncheck all checkBoxes in my form when a button is clicked. I know that I could do
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
and so on, but I have about 35 checkBoxes, so I was hoping to use a simpler code. I keep finding stuff online that looks like this;
foreach (Control cBox in this.Controls)
{
if (cBox is CheckBox)
{
((CheckBox)cBox).Checked = false;
}
}
And I was hoping to use something like that, instead of writing checkBox1.Checked = false;
about 70 times (because I have 2 buttons, both of which need to do various things and then uncheck all the boxes.
I saw another solution that involved a Stack Panel or some type of code that looked more like Javascript or HTML than C#, and also seemed to involved writing out each checkBox.Checked status as its own line, which doesn't save me any lines of code.
Any tips would be appreciated. Thanks all :)