First of all, I would seriously rethink the UI design which has 40 check boxes. It could be some tree view with check boxed on nodes,
DataGridView
,
CheckedListBox
, or something else, and even then 40 check boxes would look suspicious.
Anyway, you can change the state of check box using this property:
System.Windows.Forms.CheckBox.Checked
:
https://msdn.microsoft.com/en-us/library/system.windows.forms.checkbox.checked%28v=vs.110%29.aspx[
^].
You can do it in cycle in different ways. If you don't have an array or collection of check boxed, just make it. It would be better to add all of them in code, not in the designer, which would mean a lot of dumb manual clicks, instead of just one loop. Alternatively, add all of them in some container control, such as
Panel
and traverse its collection of chold controls referenced by its
Controls
property:
https://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls%28v=vs.110%29.aspx[
^].
In a loop, you can use an "if" block and check up the values of the
Name
property. However, the whole idea is also bad: the property
Name
is just to support the designer, is meaningless during runtime and should better be kept meaningless.
Again, the impression is that you need to create much nicer UI design, according to your ultimate goals.
—SA