ComboBox and ReadOnly feature.

  • Thread starter Thread starter =?ISO-8859-2?Q?Marcin_Grz=EAbski?=
  • Start date Start date
?

=?ISO-8859-2?Q?Marcin_Grz=EAbski?=

Hi,

I want to set ComboBox to *read-only* state.
Only choice is *Enabled* property... but it
change text color to dark grey.
Setting ForeColor to black doesn't seem to work.
Is there any other way to change ComboBox colors
without setting: Enabled=false ?

THANX for any reply!

Marcin
 
Hi Marcin,

Are you thinking of the mode where the user can't enter own values?
Then you set

MyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

Happy coding!
Morten
 
Hi Morten,
Hi Marcin,

Are you thinking of the mode where the user can't enter own values?
Then you set

MyComboBox.DropDownStyle = ComboBoxStyle.DropDownList;

I know DropDownStyle, and DropDownList style is set in my case.
I want to get mode that i can change ComboBox only from code,
but user cannot change ComboBox's Text or SelectedItem.

If i change TextBox.ReadOnly to "true" then its backcolor is
gray, but its ForeColor is "black". So TextBox's text is much
more visible than text of "disabled" ComboBox.

Marcin
 
If i change TextBox.ReadOnly to "true" then its backcolor is
gray, but its ForeColor is "black". So TextBox's text is much
more visible than text of "disabled" ComboBox.

make a OwnerDraw combo.

more formally: set a DrawMode style to OwnerDrawFixed and add your own
drawing routine to DrawItem event. this is relatively simple.

doing that will allow you to set the Combo style to Disabled (and the user
will not be able to change the selection) but the drawing routine can draw
the combo items not grayed but with ordinary face color.

regards,
Wiktor Zychla
 
Wiktor said:
make a OwnerDraw combo.

more formally: set a DrawMode style to OwnerDrawFixed and add your own
drawing routine to DrawItem event. this is relatively simple.

doing that will allow you to set the Combo style to Disabled (and the user
will not be able to change the selection) but the drawing routine can draw
the combo items not grayed but with ordinary face color.

Thank You!

Maybe the other day i write my own ComboBox and then i
add more features to him.

I have a hope that there is a simple way possible... :(

Marcin
 
Marcin GrzÄTbski said:
I know DropDownStyle, and DropDownList style is set in my case.
I want to get mode that i can change ComboBox only from code,
but user cannot change ComboBox's Text or SelectedItem.

It sounds like you just want to control the display of a given string. Have
you considered not using the ComboBox and using a TextBox with ReadOnly set
to True?

Michael S. Malley
 
Michael said:
It sounds like you just want to control the display of a given string. Have
you considered not using the ComboBox and using a TextBox with ReadOnly set
to True?

Rather not.
I prefer my current UI and functionality.
Replacing ComboBox with TextBox on run-time doesn't look good
to me too.

I've found similar problem in NumericUpDown control.
ReadOnly==true - disables only keyboard notify but Up/down buttons are
changing values.
- Enabled==false - disables all notify but greys numbers...

Marcin
 
Back
Top