user15119989
user15119989

Reputation:

Any way to check if two checkboxes are checked at the same time

ive tried using && but it doesnt seem to work, this is what I have right now

public void checkbox1_CheckedChanged(object sender, EventArgs e)
{
    if (checkbox2.Checked)
    {

    }else if (checkbox3.Checked)
    {

    }else if (checkbox2.Checked && checkbox3.Checked)
    {
        //this doesnt seem to work just executes the code in one of the two if statements above//
    }
    else
    {

    }
}

I want to make it run some code if both of those checkboxes are checked at the same time (checkbox2 and checkbox3) but the && operator doesnt seem to work for that, atleast in my case

Upvotes: 0

Views: 378

Answers (1)

EricSchaefer
EricSchaefer

Reputation: 26330

It's a problem with the order of execution.

public void checkbox1_CheckedChanged(object sender, EventArgs e)
{
    if (checkbox2.Checked && checkbox3.Checked)
    {

    }
    else if (checkbox2.Checked)
    {

    }else if (checkbox3.Checked)
    {

    }
    else
    {

    }
}

Upvotes: 3

Related Questions