How do I set combobox read-only or user cannot write in a combo box only can select the given items?

C#Combobox

C# Problem Overview


I am facing a problem in setting the combo property such that only user can select the values form given items, but I cannot write in the combo box.

How can I do so in C#?

C# Solutions


Solution 1 - C#

Just change the DropDownStyle to DropDownList. Or if you want it completely read only you can set Enabled = false, or if you don't like the look of that I sometimes have two controls, one readonly textbox and one combobox and then hide the combo and show the textbox if it should be completely readonly and vice versa.

Solution 2 - C#

I think you want to change the setting called "DropDownStyle" to be "DropDownList".

Solution 3 - C#

In the keypress event handler:

e.Handled = true;

Solution 4 - C#

Make the DropDownStyle to DropDownList

stateComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

Solution 5 - C#

Try this:

    private void comboBox1_KeyDown(object sender, KeyEventArgs e)
    {
        // comboBox1 is readonly
        e.SuppressKeyPress = true;
    }

Solution 6 - C#

The solution is to change the DropDownStyle property to DropDownList. It will help.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBadrView Question on Stackoverflow
Solution 1 - C#Hans OlssonView Answer on Stackoverflow
Solution 2 - C#RyanView Answer on Stackoverflow
Solution 3 - C#Naa3erView Answer on Stackoverflow
Solution 4 - C#Tijo TomView Answer on Stackoverflow
Solution 5 - C#FransView Answer on Stackoverflow
Solution 6 - C#scatterbraiinView Answer on Stackoverflow