uneditable comboBox

J

justin.creasy

I was wondering if anyone knew how to make a comboBox that cannot be
edited, but works in every other way. I have tried setting the
<comboBox name>.Enabled to false, but then I can't use the comboBox. I
merely want a way to have a comboBox with multiple items that can be
choosen from the drop down, but not allow text to be entered. Another
idea I had was to capture every keystroke, but that's a lot of
computing and my UI is already pretty intense. Any ideas would be
greatly appreciated.
 
D

Daniel O'Connell [C# MVP]

I was wondering if anyone knew how to make a comboBox that cannot be
edited, but works in every other way. I have tried setting the
<comboBox name>.Enabled to false, but then I can't use the comboBox. I
merely want a way to have a comboBox with multiple items that can be
choosen from the drop down, but not allow text to be entered. Another
idea I had was to capture every keystroke, but that's a lot of
computing and my UI is already pretty intense. Any ideas would be
greatly appreciated.

Try setting <comboBox name>.DropDownStyle = ComboBoxStyle.DropDownList
 
P

Paul E Collins

Daniel O'Connell said:
[non-editable ComboBox]

Try setting <comboBox name>.DropDownStyle =
ComboBoxStyle.DropDownList

Alternatively, if you want the *application* to be able to put
non-standard values in the box, but not the user, you need to override
various events, such as KeyDown, and do "e.Handled = true" so that the
event won't propagate. Make sure you handle things like Ctrl+V for
pasting text.

P.
 
J

justin.creasy

Thanks, I had thought of catching the events. I did not want to do that
b/c of how much I already have going on in my UI. Daniel's idea of just
setting the DropDownStyle to DropDownList worked perfectly. It makes
sense now that I think about it, but I still don't know why there isn't
a ReadOnly attribute. Oh well, thanks a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top