Search code examples
c#visual-studio-2008checkboxmessagebox

If Both Checkboxes flag false do?


I am getting frustrated with Google query's on code so I'll just ask all you experts.

I have a <500 line program that lists files from clearcase in a tree now I want to click on them and check them in/out. The checkout part I can accomplish via command line or plugin (::whew:: clearcase is not easy to program with) anyhow I have to checkboxes one for checkin one for checkout and if neither are selected (both false) I want it to notify the user. I have the following code and it works...except that it always displays the "not selected" message since one flag is always false.

if (checkBox1.checked == true
{
   MessageBox.Show("this")
}
if (checkBox2.checked == true 
{
   MessageBox.Show("THAT")
}
if (checkbox1.checked == false | checkbox2.checked == false)
{
   MessageBox.show("You didn't select this or THAT")
}

After the first choice it always says "THAT" or "this" then "You didn't select this or THAT"

Also I have the checkboxes setup so that when you check one it unchecks the other, but both can be false.


Solution

  • You want to check that they are both false, and that is done with a logical AND. The vertical bar represents an OR condition.

    if (checkbox1.checked == false && checkbox2.checked == false)
    {
        MessageBox.show("You didn't select this or THAT")
    }
    

    That should do what you are looking for.