mercredi 15 avril 2020

Checkbox Checked status change depends on five other checkboxs

I have totally 6 checkbox's. I want to check or uncheck 6th check box based on the status of remaining 5 checkboxes. If any of the two check boxes or more is checked true then 6th one should be true if not then false. I have tried different if statements but not successful. so far the best i found is this logic

  private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox1.Checked == true)
        {
            if (checkBox2.Checked == true || checkBox3.Checked == true || checkBox4.Checked == true || checkBox5.Checked == true)
            {
                checkBox6.Checked = true;
            }
            else
            {
                checkBox6.Checked = false;
            }

        }
        else
        {
            if ((checkBox2.Checked == true || checkBox3.Checked == true) || (checkBox4.Checked == true || checkBox5.Checked == true))
            {
                checkBox6.Checked = true;
            }
            else
            {
                checkBox6.Checked = false;
            }

        }
    }

This logic is not working when i have only 1 checkbox checked true. in that condition the 6th one should be false but not. Any suggestions??

Aucun commentaire:

Enregistrer un commentaire