Search code examples
.netdrop-down-menucomboboxbackcolor

How to set background color of the textbox portion of a combobox when dropdown style is DropDownList in .NET?


I'm coding in VB.NET. I have a requirement that my combobox display as mandatory, which means the backcolor must be yellow. The dropdownstyle is DropDownList so the user can type in the textbox field of the combobox but only find the items in the combobox.

If I set the backcolor of the combobox to yellow, the dropdown panel of the combobox is yellow, but I am unable to get the textbox field to display with a yellow background.

This only appears to be a problem when the dropdownstyle is DropDownList.

I've looked at many questions about this online but they mostly address the dropdown panel, not the textbox field, or else they are WPF or Web solutions. Can anyone help?


Solution

  • If I remember right, that's an issue with the DropDownList, but I'm not sure. But if that's the case and you want it yellow anyway, you can put a textbox in top of the combobox and display the value of it.

        private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
              ΤextBox.Text = ((YourType)ComboBox.SelectedItem).YourValue;
           
        }