-2

I have a textBox set to ReadOnly and I want a similar look for my comboBox so that my User knows that this field can't be edited.

I tried setting Enabled to false but Client doesn't like its result due to poor readability.

textBox.ReadOnly = true; //readable

comboBox.Enabled = false //not readable

My goal is to replicate the style of the ReadOnly textBox into the comboBox's style.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291

2 Answers2

1

One solution is to render the page based on the field's editability: If it is read only then create a read only textbox with the given value. If it is editable then create a normal combobox. This way only 1 value has to be rendered which may be beneficial for you as well!

Daniel
  • 126
  • 1
  • 12
  • Sounds good. I was instead trying to search for a way to change the style used for disabled items. Your method seems better though. @Daniel Can you please guide me a bit more about rendering the items this way? Maybe share a link to some code that demonstrates something similar please. – Shakaib Saleem Jan 02 '19 at 12:36
  • As you mentioned it has to be solved in WinForms. Unfortunately, I have no knowledge on how to do it in an elegant way in WinForms. For example, in WPF, you have data template selector which could solve your problem. (One data template would be the combobox, the other data template would be the textbox.) – Daniel Jan 03 '19 at 10:02
0

The answer is given here:

Just change the DropDownStyle of the ComboBox from DropDown to DropDownList. It works very fine for me.

golden96371
  • 350
  • 6
  • 19