locked
How to uncheck a checkbox in C#?

    Question

  • I am new to programing and was wondering how to uncheck a checkbox when the other check box is check this is the code i need:
    checkBox1.???
    Tuesday, August 30, 2011 12:38 AM

Answers

  • Hello
     //Suppose You have 3 checkbox. You will check or uncheck in this events 
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox1.Checked == true)
          { checkBox2.Checked = false; checkBox3.Checked = false; }
        }
    
        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox2.Checked == true)
          { checkBox1.Checked = false; checkBox3.Checked = false; }
        }
    
        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox3.Checked == true)
          { checkBox2.Checked = false; checkBox1.Checked = false; }
        }
    


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Tuesday, August 30, 2011 4:26 AM
  • //if you want to check checkBox2 (and uncheck checkBox1):
    checkBox2.Checked = !checkBox1.Checked;
    


    Mitja
    Tuesday, August 30, 2011 7:49 AM

All replies

  • To Uncheck:

         checkBox1.Checked = false;

     

    To check:

     

        checkBox1.Checked = true;

     

     

     

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, August 30, 2011 12:41 AM
    Moderator
  • you can write this code in checkbox2_checkedchanged  events:

    checkbox1.Checked=false;




    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, August 30, 2011 12:57 AM
  • Hello
     //Suppose You have 3 checkbox. You will check or uncheck in this events 
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox1.Checked == true)
          { checkBox2.Checked = false; checkBox3.Checked = false; }
        }
    
        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox2.Checked == true)
          { checkBox1.Checked = false; checkBox3.Checked = false; }
        }
    
        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
          if (checkBox3.Checked == true)
          { checkBox2.Checked = false; checkBox1.Checked = false; }
        }
    


    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Tuesday, August 30, 2011 4:26 AM
  • Place both checkboxes inside a panel or groupbox or any such container. After this the CheckBox is automatically unchecked when other CheckBox is checked.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, August 30, 2011 4:53 AM
  • //if you want to check checkBox2 (and uncheck checkBox1):
    checkBox2.Checked = !checkBox1.Checked;
    


    Mitja
    Tuesday, August 30, 2011 7:49 AM
  • Place both checkboxes inside a panel or groupbox or any such container. After this the CheckBox is automatically unchecked when other CheckBox is checked.

     


    Please mark this post as answer if it solved your problem. Happy Programming!

     

    This is true for RadioButton, not CheckBox.  CheckBox controls don't effect each other this way.
    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Tuesday, August 30, 2011 4:17 PM
    Moderator
  • Ture. CheckBoxes can be all checked or all unchecked!! Which is nit true for radioButtons (in a group).
    Mitja
    Tuesday, August 30, 2011 4:56 PM