Board index » delphi » Can't set DBLookupComboBox to null

Can't set DBLookupComboBox to null

I have a DBLookupComboBox. While running the program, I create a new
database record, and the combo is initially empty. I then select a value
on the combo, and then I want to go back to null (the field is
nullable). I can't backspace, delete, Ctrl-X, select empty, or anything.
Is it possible to do it without writing code?

In addition, help says that on DBLookupComboBox you can select from
drop-down OR type as if it were an edit field. Is that true? I haven't
been able to do this, and the DBLookupComboBox does not have the 'style'
property that DBComboBox has.

 

Re:Can't set DBLookupComboBox to null


Antonios,
  a DBLookupComboBox's Text is read-only, so no, you can't simply enter
text, and that means you can't blank it out, either.  It can only display
what is in the underlying table.  When you type into the edit box, it
scrolls to the nearest value in the lookup table.  I don't see anything in
the Delphi  help that says you can type in as if it were an edit field.
That sounds like the DBComboBox, not the DBLookupComboBox.
-Howard

Re:Can't set DBLookupComboBox to null


procedure dblookupcomboboxKeyDown(Sender: TObject; var Key: Word;
                   Shift: TShiftState);
begin
   if Key = VK_DELETE then
      TDBLookupComboBox(Sender).Field.AsString := '';
end;

John Pierce

Re:Can't set DBLookupComboBox to null


in keydown event insert this code:

if Key = VK_DELETE then DBLookupCombo.KeyValue := Null;

where DBLookupCombo is your component's name

Alex D.M.

Re:Can't set DBLookupComboBox to null


Quote
Howard Moon wrote:
> Antonios,
>   a DBLookupComboBox's Text is read-only, so no, you can't simply enter
> text, and that means you can't blank it out, either.  It can only display
> what is in the underlying table.  When you type into the edit box, it
> scrolls to the nearest value in the lookup table.  I don't see anything in
> the Delphi  help that says you can type in as if it were an edit field.

In the Delphi Help Index, choose "DBLookupComboBox component", then choose
"Displaying and editing data in list and combo boxes". That's where it says
what I said. Probably an error in the Help.

Thanks all for the help, I'll use the suggested KeyDown event.

Re:Can't set DBLookupComboBox to null


  Yeah, that's an error in the Help.  You can't enter new data via a lookup
control.  If you select the section "Displaying and editing data in lookup
list and combo boxes", you will see the correct information about how lookup
data-aware controls work.
-Howard

Quote
"Antonios Christofides" <A.Christofi...@hydro.ntua.gr> wrote in message

news:3A55E403.DDCB96B4@hydro.ntua.gr...
Quote
> Howard Moon wrote:

> > Antonios,
> >   a DBLookupComboBox's Text is read-only, so no, you can't simply enter
> > text, and that means you can't blank it out, either.  It can only
display
> > what is in the underlying table.  When you type into the edit box, it
> > scrolls to the nearest value in the lookup table.  I don't see anything
in
> > the Delphi  help that says you can type in as if it were an edit field.

> In the Delphi Help Index, choose "DBLookupComboBox component", then choose
> "Displaying and editing data in list and combo boxes". That's where it
says
> what I said. Probably an error in the Help.

> Thanks all for the help, I'll use the suggested KeyDown event.

Other Threads