In my WinForms application there is a ComboBox with default values. The user should be able to add items to the ComboBox or rename existing items.

I want the design to be simplistic. This was my initial approach:

  • If the user types something in to the ComboBox and hits enter and the item exists, select it. If the item does not exist, add it.

  • If the the ComboBox is empty when the user hits enter, delete the item at the current index.

This worked alright, except for these two problems:

  1. Because it was a custom user interface control, the functionality is not intuitive.

  2. If the user deletes an item from the ComboBox and there are items after it, their indices are adjusted accordingly. Basically, every item index after that item is bumped down 1. This is bad because once an item is added, its index should not be changed as other services may depend on it. Essentially, items should not be allowed to be removed. Only renamed. Possibly to blank if they are no longer needed.

The only real solution I can think of is to have a separate dialog but I cannot envision a proper design of one.

Here's an example for the first implementation one would think of:

  1. Have a menu item open up a dialog with the purpose to add or rename items of the ComboBox.

  2. Have a TextBox for every item in the ComboBox in this dialog window. If the last TextBox is not empty, add another one (or have a button to add another TextBox).

I suppose this approach is fine, but I don't like it for a couple reasons.

  1. If the user has a lot of items in the ComboBox, the dialog window would be huge or require a scroll bar.

  2. This approach requires a menu item, a corresponding dialog window, and a potential large amount of dynamic controls.

I've been trying to think of a better way to approach this but I am not having any luck.

  • 1
    You should never ever have anything depend on the position of something else in a list. Learn how to use a combination of value (identifier) and display text (what the user sees) for each item in comboboxes and the like. Users can then re-order and delete items to their hearts desire. They will only affect the index of items, but won't affect their display test or their identifying values. It will save you (and people using your work) numerous headaches. Sep 9, 2011 at 8:12

3 Answers 3


It seams you are using ComboBox for that it have not been created. ComboBox stores a fixed list of items to select. If you need to edit this list, use separated form to edit items. It would be more intuitive, trust. Otherwise, please, use grid, for example. It is more "editable".


What you are looking for is (I think) an auto complete text box.

This allows the user to add any text at all, but matches the input against a predefined list and then allows the user to select one of the items from that list. You might see this where the user has to enter a state or country.

In your case you want to add any input that isn't already on the list to the list - which is possible.

Your requirement to delete is also possible - but note that in Outlook which has similar functionality when entering e-mail recipients it uses Shift+Delete to remove items.

This blog post has an example of how to create one in WinForms. I won't repeat the code here as it's not necessary.


Even at this late date, this post is still useful. To add an item a user has keyed in to the ComboBox control,

  1. Select the ComboBox (we're in design mode in Visual Studio),
  2. View its properties.
  3. Select the Events view.
  4. Add the KeyDown event method.
  5. in the KeyDown event's method, check the KeyEventArgs e.KeyCode. If the user presses the Enter key, (Keys.Enter), check to see if the item is already in the Items list:

    private void cmbUserNouns_KeyDown(object sender, KeyEventArgs e) {

    string s = cmbUserNouns.Text;

    if (e.KeyCode == Keys.Enter)


    // if item exists, select it. if it does not exist, add it.

    if (!cmbUserNouns.Items.Contains(s))






I just tested this out and it seems to be working nicely!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.