tags:

views:

2948

answers:

8

I do not want the user to be able to change the value displayed in the combobox. I have been using Enabled = false; but it is very readable like when setting a Textbox.ReadOnly = true;

Is there is a way of accomplishing this?

Thanks,

Kishore.

+1  A: 

The best thing I can suggest is to replace the combo-box with a read-only textbox (or just perhaps a label) - that way the user can still select/copy the value, etc.

Of course, another cheeky tactic would be to set the DropDownStyle to DropDownList, and just remove all other options - then the user has nothing else to pick ;-p

Marc Gravell
A: 

Not sure if this is what you're looking for but...

Set the DropDownStyle = DropDownList

Then on the SelectedIndexChanged event

If (ComboBox1.SelectedIndex <> 0)
{
    ComboBox1.SelectedIndex = 0
}

This ugly part is that they will "feel" like they can change it. They might think this is an error unless you give them an alert telling them why they can't change the value.

Dan Williams
+1  A: 

You can change the forecolor and backcolor to the system colors for an enabled combo box, although this may confuse the users (why have it if they can't change it), it will look better.

Tom Anderson
+5  A: 

Here is an interesting solution to it

Joe
A: 

make DropDownStyle property to DropDownList instead of DropDown

A: 

Why don't you just use a text box? Text box has a "Read only" property, and since you want your combo box only to display data, I don't see why you would need a combo box.

An alternative is that you just cancel out the input for the "on value changed" event. That way you will be displaying your information no mater what user does ...

Rekreativc
A: 

Actually, its rather simple:

Private Sub combobox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles combobox1.KeyDown

' the following makes this the combobox read only

    e.SuppressKeyPress = True

End Sub

Rob
A: 

Here is the Best solution for the ReadOnly Combo.

private void combo1_KeyPress(object sender, KeyPressEventArgs e) { e.KeyChar = (char)Keys.None; }

It will discard the keypress for the Combo.

Enjoy...

Manish parmar

Manish