Question

I'm writing a GUI in C#, Visual Studio 2008, using the Designer and WinForms. I've got a ComboBox control, and I'd like it to only allow to select from the provided options and not to accept a user-entered string. It doesn't appear to have a ReadOnly property, and disabling it hinders the readability of the control (as well as disallowing user-selection).

Was it helpful?

Solution

Set DropDownStyle to "DropDownList"

OTHER TIPS

Set the ComboBox.DropDownStyle property to ComboBoxStyle.DropDownList.

Another simple way to go about it.

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

Use code similar to the following to set the allowed options and only those options.

comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
comboBox1.Items.AddRange(new object[] {
    "One",
    "Two",
    "Three",
    "Four"});

Try using a DropDownListbox

My requirement : once user giving an input through combo-box they can not change the value before submit it. They can read only that value.

As per my requirement i do the following things.

1) Get input from user through combo-box.
2) Copy the value of combo-box to a text-box(which is read only and invisible).
3) False the visibility of combo-box.
4) True the visibility of read only text-box.

Do this with events.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top