If one checkbox is checked, set the other to unchecked

前端 未结 9 1713
Happy的楠姐
Happy的楠姐 2021-01-13 10:06

I have two checkboxes on my form; chkBuried and chkAboveGround. I want to set it up so if one is checked, the other is unchecked. How can I

9条回答
  •  自闭症患者
    2021-01-13 10:46

    I would prefer radio buttons, but you can do something like this:

    public void CheckACheckBox(Checkbox ck)
    {
        foreach (Control ckb in this.Controls)
        {
           if ((ckb is CheckBox) && (ckb == ck))
              ck.Checked = true;
           else
              ck.Checked = false;
        }
    }
    

提交回复
热议问题