Board index » delphi » How can I stop DBComboBox list dropping down?

How can I stop DBComboBox list dropping down?

Hi everybody,

My experience with Delphi 4 is still fairly limited, so please excuse what
may be a silly question.

On a form I have two DBComboBoxes, with DataSource pointing to a Paradox
table, TTMaterial.  If the table is empty, I want to stop the user from
editing the combo boxes in question.  On the OnKeyPress event, I put the
following code:-

    if DataModule1.TTMaterial.RecordCount = 0 then
        abort;

... which works fine in the event of the user trying to type a value in.
However, I can't find way to stop the drop-down list appearing when the user
clicks the drop-down arrow (OnClick only works on the edit region).  I've
tried putting the same code on OnDropDown, and found it at best unstable -
it aborts, but leaves a black line at the bottom of the combo box, at worst
totally ineffective - the list still drops down.  The latter seems to occur
when the user has changed databases from one which has data in the Material
table to one which has none; however I have established that the RecordCount
is deffinitely 0.

I'd appreciate any useful suggestions.

Thanks in advance

 

Re:How can I stop DBComboBox list dropping down?


Quote
"Ruth Buckner" <drscientific-r...@powerup.com.au> wrote in message

news:3a90c410@grissom...

Quote
> Hi everybody,

> My experience with Delphi 4 is still fairly limited, so please excuse what
> may be a silly question.

> On a form I have two DBComboBoxes, with DataSource pointing to a Paradox
> table, TTMaterial.  If the table is empty, I want to stop the user from
> editing the combo boxes in question.  On the OnKeyPress event, I put the
> following code:-

>     if DataModule1.TTMaterial.RecordCount = 0 then
>         abort;

Have you thought about enabling/disabling the controls instead. Where this
is done depends on the architecture of your application. One place is in the
table's events: AfterOpen, AfterInsert, AfterDelete. Another is in the
form's OnCreate or OnShow, and any OnClick that adds or removes records.

Re:How can I stop DBComboBox list dropping down?


Quote
Bruce Roberts <b...@bounceitattcanada.xnet> wrote in message

news:5fbk6.30$TW.365@tor-nn1.netcom.ca...

Quote

> Have you thought about enabling/disabling the controls instead. Where this
> is done depends on the architecture of your application. One place is in
the
> table's events: AfterOpen, AfterInsert, AfterDelete. Another is in the
> form's OnCreate or OnShow, and any OnClick that adds or removes records.

Thanks for the reply Bruce,

Yes, it crossed my mind to use enable/disable.  The reason I wanted to do
things the way I described was to keep the ComboBoxes' appearance consistent
with several DBEdits on the same form, which at present I make read-only,
along with a message to the user, rather than disabling them.  However using
enable/disable on all my db controls may be the answer.

Quote
> "Ruth Buckner" <drscientific-r...@powerup.com.au> wrote in message
> news:3a90c410@grissom...
> > Hi everybody,

> > My experience with Delphi 4 is still fairly limited, so please excuse
what
> > may be a silly question.

> > On a form I have two DBComboBoxes, with DataSource pointing to a Paradox
> > table, TTMaterial.  If the table is empty, I want to stop the user from
> > editing the combo boxes in question.  On the OnKeyPress event, I put the
> > following code:-

> >     if DataModule1.TTMaterial.RecordCount = 0 then
> >         abort;

Other Threads