I have some elements in a ComboBox (WinForms with C#). I want their content to be static so that a user cannot change the values inside when the application is ran. I also do not want the user adding new values to the ComboBox
4 Answers
Use the ComboStyle property:
comboBox.DropDownStyle = ComboBoxStyle.DropDownList;

- 7,123
- 6
- 30
- 24
-
40This can also be set in the properties window of the designer. – Jeffrey Feb 28 '09 at 18:43
-
4With recent versions you can use `combo.Properties.TextEditStyle = DisableTextEditor` – Keysharpener Jan 08 '16 at 17:04
This is another method I use because changing DropDownSyle
to DropDownList
makes it look 3D and sometimes its just plain ugly.
You can prevent user input by handling the KeyPress
event of the ComboBox like this.
private void ComboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}

- 30,617
- 60
- 187
- 303
-
4
-
3@StinkyCat That doesn't change the look of the popped up list, only the control in the form. – Logarr Mar 04 '13 at 22:48
-
You have to handle right click menu where you have option `Paste` too. I've no idea how right now. – Sinatr Apr 17 '13 at 10:18
-
3Ok, to remove `Paste` you will have to create fake empty context menu and assign it to the ComboBox. – Sinatr Apr 17 '13 at 10:27
Yow can change the DropDownStyle in properties to DropDownList. This will not show the TextBox for filter.
(Screenshot provided by FUSION CHA0S.)

- 239,200
- 50
- 490
- 574

- 953
- 7
- 3
I tried ComboBox1_KeyPress but it allows to delete the character & you can also use copy paste command. My DropDownStyle is set to DropDownList but still no use. So I did below step to avoid combobox text editing.
Below code handles delete & backspace key. And also disables combination with control key (e.g. ctr+C or ctr+X)
Private Sub CmbxInType_KeyDown(sender As Object, e As KeyEventArgs) Handles CmbxInType.KeyDown If e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Then e.SuppressKeyPress = True End If If Not (e.Control AndAlso e.KeyCode = Keys.C) Then e.SuppressKeyPress = True End If End Sub
In form load use below line to disable right click on combobox control to avoid cut/paste via mouse click.
CmbxInType.ContextMenu = new ContextMenu()

- 2,217
- 2
- 19
- 33