We help IT Professionals succeed at work.

Combo Boxes final text value has to be on the list.

Hello all,

I cannot seem to find the answer that I am looking for so... I have a combo box with the DropDownStyle set to DropDown. I want users to be able to type and get the suggested options, but I do not want user's to type and leave a value that is not on the list. I have the SuggestAppend set for AutoComplete, but users can set the combo boxes text value to something that is not on the list.  Originally, I had the DropDownStyle set to DropDownList but the color change bothered me and all the solutions I found did not seem to let me change the BackColor. Can some please help me with getting the BackColor changed to "white" for a DropDownList  combo box or help me programically change the behavior of the combo box to not allow the value to equal something that is not on the list?

**Change the FlatStyle property to Popup is not an option.

Thank you for your assistance.
Watch Question

Since I'm not sure which version of .NET you are using. Here is a rudimentary solution to your question. I would create a Leave() event on your ComboBox that looks something like this:
        private void comboBox1_Leave(object sender, EventArgs e)
            message.Text = string.Empty;

            string t = comboBox1.Text;
            if (!comboBox1.Items.Contains(t))
                comboBox1.Text = string.Empty;
                //Here you would update some text element on the form informing the user they must only provide a value in the list.
                message.Text = "You must choose from the list.";


Open in new window

If this isn't what you were asking, can you maybe provide a bit of sanitized code?


Thank you for the assistance!!!