How to allow the insertion of information in the database using DBLookupComboBox?

1

I have a DBLookupComboBox that captures the data in the Species table so that the user can select what he needs, after which this data is saved in the Animal table. p>

My question is how do I get the user to add a new record to DBLookupComboBox at runtime and save it in the database after the user confirms that they want to do so.

    
asked by anonymous 14.03.2015 / 03:42

1 answer

1

If your idea is to get the user to edit the selected content in DBLookupComboBox , this may not be possible since the purpose of this control is to list the data of a table as specified in the ListSource property.

If this is what you want to do, maybe DBComboBox might be better for this case.

What you can do to get around this is through the onClick event of a button.

const
MSG1 = 'Digite uma nova espécie:';
MSG2 = 'Tem certeza que deseja gravar a espécie %s no banco?';
var
 Entrada: string;
begin
Entrada := InputBox(Caption, MSG1, '');
if Length(Entrada) = 0 then Exit;
if MessageDlg(Format(MSG2, [Entrada]), mtConfirmation, [mbYes, mbNo], 0) = mrNo then Exit;

Tabela1.Append;
Tabela1.FieldByName('Campo1').AsString := Entrada;
...

You must bind the ListSource property of DBLookupComboBox to DataSource of the desired table.

    
14.03.2015 / 22:40