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?

Recommended Answers

All 2 Replies

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();

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.