Hello I’m trying to display items in a combobox but nothing appears. I used the property:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add("Item 1");
}
To add in an item but when I run my app the item doesn’t show in the drop downlist.
I looked at a lot of MSDN articles but none have worked or perhaps I’m not getting it.
Is there something I’m missing with this?
If your
ComboBoxis initially empty, then yourSelectedIndexChangedevent is never getting fired because there is no selection to change. I would add the items to theComboBoxsomewhere else, perhaps in anInit()function.You might be misunderstanding how they work. Once you create the combobox and add it to some kind of UI container, the .NET Framework takes care of displaying it and showing the items it is initialized with when you click it. You don’t need to manually handle making items show. Basically, what I’m getting at is if you make a combobox and add some items to it, then it will automatically show them whenever the control is clicked.
The
SelectedIndexChangedevent is used typically used to make something happen when you select a different item from theCheckBoxthen what it is currently showing.