Joan Venge
Joan Venge

Reputation: 330892

Is it possible to change a Winforms combobox to disable typing into it?

So that it just allows selecting items already inside, but not allow typing/editing the text inside it?

Upvotes: 92

Views: 43730

Answers (2)

Shane Fulmer
Shane Fulmer

Reputation: 7708

Set ComboBox.DropDownStyle to ComboBoxStyle.DropDownList.

Upvotes: 182

teynon
teynon

Reputation: 8288

After trying ShaneFulmer's answer, I noticed that the style of the drop down was changed. This was a problem for me and apparently there is no good way of changing it. (Background color doesn't actually change it.)

I ended up adding a keypress handler to prevent adding text.

private void myCombo_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = true;
}

Upvotes: 12

Related Questions