A simple task is to go through all the checkboxes in this form and this taba and mark them as not selected. I found in my opinion the right solution:

foreach (Control c in this.Controls) { CheckBox cb = c as CheckBox; if (cb != null && cb.Checked) { cb.Checked = false; } } 

But it does not work! And I do not understand why. I watched the debugger - cb = null. Why can this be? Which way to dig? ..

  • if cb == Null , then in с is not a CheckBox at all, look at what type it is - yapycoder
  • System.Windows.Forms.CheckBox - Mobyman

1 answer 1

In my opinion, the matter of recursion. Should work

 private void button1_Click(object sender, EventArgs e) { foreach (Control control in this.Controls) { this.UncheckAllCheckBoxes( control ); } } private void UncheckAllCheckBoxes(Control control) { foreach (Control c in control.Controls) { this.UncheckAllCheckBoxes( c ); } var cb = control as CheckBox; if (cb != null && cb.Checked) cb.Checked = false; } 
  • Thanks a lot, but they helped me on stackflowflow. And the thing was that I simply did not specify the name of the tab. Here is such a nonsense. - Mobyman