Thanks for the extra information. Using your steps I've been able to reproduce the error. It looks like if you delete an item while the drop-down is open and then try and leave the control, the selected index doesn't get a chance to update itself.
You'll then get this error with the index parameter being equal to the index of
whatever item you deleted.
Really, the best way to add new items to a combo-box would be to use a separate control, i.e. a textbox, with a button to add that value to the list. The combo-box is only really intended for item selection. However, if you really want to do things this way, to get around this quirk you could handle the DropDownClosed event of the combo-box and do a quick range check yourself. Here's some example code:
-
private void comboBox1_DropDownClosed(object sender, EventArgs e)
-
{
-
ComboBox c = sender as ComboBox;
-
if (c.SelectedIndex >= c.Items.Count) c.SelectedIndex = c.Items.Count - 1;
-
}
-
Using this method, when the drop-down closes if there is a mismatch between the selected index and the number of items in the list (an item has been deleted), then the last item in the list is selected.
There are still other issues with this method that you'll probably want to clear up. For example, try typing some text, and pressing enter while the drop-down is open. The item will be added to the list twice.