checkbox - Counting number of current checked boxes and output that number in c# -


i trying count number of current checked "checked box" in group box. have 10 check boxes.

i been trying code managed count upward if checked box not other way around. adding (but not +1 each time).

so approach have take count number of current (not incrementing) checked boxes? thank you

int checkedboxes = 0;  private void checkbox1_click(object sender, eventargs e) {     checkbox check = (checkbox)sender;     bool result = check.checked;      if (result == true)     {         btndone.enabled = true;     }      foreach (control c in grptoppings.controls)     {         checkbox cb = c checkbox;         if (cb != null && cb.checked)         {             checkedboxes += 1;             int how_many = checkedboxes;         }     } }  private void btndone_click(object sender, eventargs e) {     string name = textbox_ordername.text;     messagebox.show("\nhow many: " + checkedboxes, "it done",     messageboxbuttons.ok); } 

just move assignment of checkedboxes in event checkbox1_click looping on child controls again , count should reset.

int checkedboxes;  private void checkbox1_click(object sender, eventargs e) {     checkedboxes = 0;     checkbox check = (checkbox)sender;     bool result = check.checked;      if (result == true)     {         btndone.enabled = true;     }      foreach (control c in grptoppings.controls)     {         checkbox cb = c checkbox;         if (cb != null && cb.checked)         {             checkedboxes += 1;             int how_many = checkedboxes;         }     } } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -