I have a listbox and a button on my form. Listbox contains of 3 elements: House, People, Outdoor. I have also created 3 forms to represent the values from the listbox.
I would like to user to highlight the item on the listbox and after clicking the button I would like to open the form selected by the user.
How can I achieve this? I have tried this link: Calling new Form by clicking an item on the ListBox but without any success.
I have tried:
public Select()
{
InitializeComponent();
listBox1.Click += OnListBoxItemClick;
}
private void OnListBoxItemClick(object sender, EventArgs e)
{
var form2 = new House();
House.ShowDialog();
}
- This would only allow me to open one form. How can I assigned different forms to be open with different values from listbox?
- I would like the form to open after I click on the button, not the value in the listbox, how to achieve it?