I have a combobox with DropDownStyle set to DropDown. I want it to be possible that a user can type in a new item. By leaving the control I want to add the new item to the underlaying datasource.
However, when the user types in a name that already exists, it must select the existing one.
How can I do this?
Try this approach:
If user types in unrecognized text ComboBox control sets SelectedItem to null. So we create new item, set it’s properties and add it to the list. Next we rebind list to DataSource to let ComboBox understand there was a change. Part that clears DataSource and sets it again will not be necessary if you use BindingList instead of simple list.
EDIT: forgot to add – this will work much better if you set AutoSuggest and AutoSuggestList.