954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The choosen tems in combobox will take me to another form

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?

csharp_user
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 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();
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

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

csharp_user
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: