I am looking for a way to check if the user has checked more than one box.
if (checkBox1.Checked == true)
if (checkBox2.Checked == true)
MessageBox.Show("Please select one car type");
else if (checkBox3.Checked == true)
MessageBox.Show("Please select one car type");
The problem with the way I have it is it only shows the message box if the user checks the first checkbox then if they select the second one the messagebox.show comes up. But if the user selects the second and third the message doesnt show up.
I do understand I can do it the way I have below but I think there is a better way with less code. Because by doing it the way I have below the message pops up twice if checkbox 2 is checked.
if (checkBox1.Checked == true)
if (checkBox2.Checked == true)
MessageBox.Show("Please select one car type");
else if (checkBox3.Checked == true)
MessageBox.Show("Please select one car type");
if (checkBox2.Checked == true)
if (checkBox1.Checked == true)
MessageBox.Show("Please select one car type");
else if (checkBox3.Checked == true)
MessageBox.Show("Please select one car type");
Or as a commenter pointed out, use a radio button (which allows at most one selection).