Im just trying to get for loops to work properly and just basically messing around. This does actually work properly; yes i realize the names are retarded but they just came out :P
Basically in this program you highlight an item in the textbox, and when you press ok that selected item will come up in a messagebox and say "you have selected so and so"
Anyway... my question is how would i get this to display "You have selected nothing" when the user clicks the ok button and nothing is selected in the listbox.
for
(int counter = 0; counter < listBox1.SelectedItems.Count; counter++) switch (listBox1.SelectedItems[counter].ToString()){
case "Boogers": MessageBox.Show("One of your chioces was Boogers"); break; case "Cheese": MessageBox.Show("One of your choices was Cheese"); break; case "Banana": MessageBox.Show("One of your chioces was Banana"); break; case "Chocolate": MessageBox.Show("One of your choices was Chocolate"); break;
I think the solution is simple:
the_developer_cali
You just have to add one more case:
case "Chocolate":
MessageBox.Show("One of your choices was Chocolate");
break;
default: MessageBox.Show("You have selected nothing");
break;
Dan Hadfield
Thank you that helped alot.
I did actually try to put that in at one point but i was putting it in the wrong place i guess.
partt
if (listBox1.SelectedItems.Count == 0 )
MessageBox.Show("You have selected nothing");
else
{
// do your for loop here. . .
}
denszon
El locolito
because you are working off count -
if count = 0, the for loop doesn't execute.
Jon Russell
Blair,
Can you please modify your signature These forums are not the appropriate location for a political statement.
Thank you
David
Jeff B.