Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Apr : How can I make ComboBox Read Only?

www.cryer.info
Managed Newsgroup Archive

How can I make ComboBox Read Only?

Subject:How can I make ComboBox Read Only?
Posted by:"Dave Atkin" (sepultur..@optusnet.com.au)
Date:Tue, 5 Apr 2005 16:45:39

Hi everybody,

Does any one have any ideas how to add a ReadOnly property to a
TCustomComboBox descendant?
On a form that contains many Edit controls & a few Combo Boxes, I loop
through the form's controls and set the Color & ReadOnly properties
depending on the state of variable bCanEdit - the problem is TComboBox
doesn't have a ReadOnly property (a glaring omission by Microsoft IMHO).  As
I'm using my own custom ComboBox descendant, I thought I'd build in a
ReadOnly property.  Overriding the OnKeyDown, & OnKeyPress events to trap &
throw away any input from the keyboard is easy, the only way to prevent the
user pressing the DropDown button with the mouse seems to be to set Style
property to csSimple when ReadOnly is true, and set it back again when
ReadOnly is false - I can live with that at a pinch - but then the user can
always paste something in using the default ContextMenu.  I can get around
that by adding a ReadOnlyText property and setting Text := ReadOnlyText in
the OnChange event but I'm not keen on the Brute Force approach.  is there
any way to get the handle of the TEdit portion of the ComboBox & send a
EM_READONLY message to it.  Ideally I'd like to keep the DropDown button
visible when ReadOnly is true, to indicate to users that the control is a
ComboBox, but prevent the user from dropping it down.  Setting the
ComboBox.Enabled property to false is not an option, as users still need to
be able to copy text from the control.  Any ideas would be gratefully
received.

Regards,
Dave Atkin.

Replies:

www.cryer.info
Managed Newsgroup Archive