Problem
I’d want to create a “select-only” ComboBox with a list of options for the user to choose from. In the text portion of the ComboBox control, typing should be disabled.
My initial search yielded an unnecessarily complicated and erroneous suggestion for capturing the KeyPress event.
Asked by Cory Engebretson
Solution #1
Set the DropDownStyle property to “DropDownList” to make the text area of a ComboBox non-editable. For the user, the ComboBox is now virtually select-only. This can be done in the Visual Studio designer or in C#, as seen below:
stateComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
On MSDN, you can find documentation for the ComboBox DropDownStyle property.
Answered by Cory Engebretson
Solution #2
The DropDownStyle settings can be found under the Properties of the selected ComboBox to add a Visual Studio GUI reference:
This will add the line specified in the first answer to the Form automatically. InitializeComponent() in Designer.cs, as follows:
this.comboBoxBatch.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
Answered by invertigo
Solution #3
Stay on your ComboBox and use the properties window to find the DropDropStyle property, then select DropDownList.
Answered by LZara
Solution #4
COMBOBOXID.DropDownStyle = ComboBoxStyle.DropDownList;
Answered by Abhishek Jaiswal
Solution #5
After selecting, do the following to continue displaying data in the input:
VB.NET
Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
e.Handled = True
End Sub
C#
Private void ComboBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
Answered by Diogo Rodrigues
Post is based on https://stackoverflow.com/questions/85702/how-can-i-make-a-combobox-non-editable-in-net