Checking if the Checkbox is checked or not dynamically in c# -
i have created checkbox dynamically button code
private void btn_add_record_click(object sender, eventargs e)q2 { checkbox deletecheckbox = new checkbox(); point p_request = new point(nxcheckbox, nycheckbox); deletecheckbox.location = p_request; deletecheckbox.name = "ch"+record_id+""; }
then checked manually need check specific checkbox name "ch"+record_id+" checked or not dynamically using code
string chechboxname = "ch1"; checkbox deletechechbox = new checkbox(); deletechechbox.name = chechboxname; if (deletechechbox.checked) { // code }
when debug code, doesn't come in if statement .. why ?
you're checking if box checked before gets checked. add together
deletechechbox.checkedchanged += deletechechboxcheckedchanged;
and add together method deletechechboxcheckedchanged can test whether or not it's been checked. can use
deletechechbox.checked = true;
to check box through code.
edit: checkbox it's name have either store global variable or through controls array in form.
foreach (control command in this.controls) { if (control.name == "ch1") { checkbox deletechechbox = (checkbox)control; if (deletechechbox.check) { //to code } } }
c#
No comments:
Post a Comment