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.
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.
Try
if (checkBox1.checked == true)
{
MessageBox.Show("this")
}
else if (checkBox2.checked == true)
{
MessageBox.Show("THAT")
}
else
{
MessageBox.show("You didn't select this or THAT")
}
or better:
if (checkBox1.checked)
{
MessageBox.Show("this")
}
else if (checkBox2.checked)
{
MessageBox.Show("THAT")
}
else
{
MessageBox.show("You didn't select this or THAT")
}
Use an if-else statement instead of just an if statement. That way it will stop after executing the first statement.
if (checkBox1.checked)
{
MessageBox.Show("this")
}
else if (checkBox2.checked)
{
MessageBox.Show("THAT")
}
else
{
MessageBox.show("You didn't select this or THAT")
}
What about
(checkbox1.checked == false & checkbox2.checked == false)
The vertical line is OR while the ampersand is AND