0

Hi,
Im new at C# and im trying to make a booking system where i have a combobox on the first form. From that form i have to choose 1 out of 3 items. Depending on which item i choose i will come to another form.

How can i get to another form when i select an item in the combobox?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by csharp_user
0

If you have only simple strings as items in comboBOx then you can do:

//in combobox_selectedIndexChanged event:
if(comboBox1.SelectedItem.ToString() == "item 1")
     new Form2().Show();
else if(comboBox1.SelectedItem.ToString() == "item 2")
     new Form3().Show();
else if(comboBox1.SelectedItem.ToString() == "item 3")
     new Form4().Show();
0

Thanks for your help.

I modified it to this:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Form2 frm2 = new Form2();
Form3 frm3 = new Form3();
Form4 frm4 = new Form4();


if (comboBox1.SelectedItem.ToString() == "item1")
frm2.Show();


else if (comboBox1.SelectedItem.ToString() == "item2")
frm3.Show();



else frm4.Show();


}

so now its working and problem solved. :)

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.