Clear Checkboxes Inside GroupBox Not Working In C# Windows Forms
In a project that i am working with, I have 18 checkboxes. Normally the code below should clear all 18 checkboxes in the groupbox.
However only 14 checkboxes are deselected. So I modified the code to this:
I applied a recursion only once to prevent infinite loop/exception. This worked for now.
private void ClearChecklist(GroupBox control) { foreach (Control checklist in control.Controls) { if (checklist is CheckBox) { ((CheckBox)checklist).Checked = false; } } }
private void ClearChecklist(GroupBox control) { if (visited_recursion <= 1) { foreach (Control checklist in control.Controls) { if (checklist is CheckBox) { ((CheckBox)checklist).Checked = false; } } visited_recursion++; ClearChecklist(grpActiveSiteCategories); } }
Comments
Post a Comment