Matt, here are some details that might be of use to you, in case you proceed with it.
I have used combo boxes in a couple of places on my forms in exactly the way you have mentioned.
In addition to the adding facility, you can also give edit & delete options to the user where the user can edit/ rename and delete the combo entries. However, you need to be extremely careful with the selected index when providing this feature as it can get pretty messy.
In my case, I have the following three items to take care of all the above mentioned functionality:
- Combo box with DropDownStyle =
DropDown
- Save button
- Delete button
Functionality is as follows:
In the combo box in addition to the items already saved by the user, I have an item --New-- at the top.
When the user has to edit/ rename an item, he should select the item from the combo, type the new name in the combo and then click Save.
If the user wants to add a new item, he should select --New-- from the combo, type in the name in the combo (this will overwrite --New--) and click Save
If the user needs to delete an item, he should simply select the item and click on Delete
I have implemented the SelectionChangeCommitted event rather than the SelectedIndexChanged, as the latter fires event if the selected index is set through code, whereas the former only when user is selecting an item in the combo box from the screen.
In addition, I have maintained a form level variable called _selectedComboID which stores the id of the currently selected combo item. It gets set in the SelectionChangeCommitted event handler. This is because, if you have to rename an entry in the combo, you will first select it. At that time the selectedIndex is correct (the one you have selected). Then since you need to rename it, you will edit the combo text and click Save. However, since you have edited the name, it now messes with the selected index. So I save it in a variable before hand when user makes the selection.
In the Save method, I have checked if _selectedComboID is same as the ID for --New--. If yes, the insertion code is fired, else the edit code. In both cases, you need to check that the name chosen by the user doesn't already exist, in addition to other validations.
If you are setting Sorted = true for your combo box, it is very important to use SelectedItem throughout your code rather than SelectedValue. This is because when you set sorted as true for a combo box, it messes up the selected values. You can refer to my post on Setting selected item in a ListBox without looping for details.
Wow, that was huge!!! Hope it helps :)