Reputation: 65
Currently using C# in Visual Studio 2013 make a program where I want something on the screen to become available once the user has selected any value from a combobox. So far I have made this:
if (cmbTickets.SelectedIndex == 10)
{
enableSeats();
}
When this is used the item on the screen becomes available only when the number ten is chosen from the combobox. I wan this to happen however when any of the options in the combobox is selected. What value should I place in the if statement to do this?
Upvotes: 0
Views: 41
Reputation: 66449
Subscribe to the SelectedIndexChanged
event.
The SelectedIndex
is -1
when no selection has been made, so just reference that.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex > -1)
enableSeats();
}
Upvotes: 1