Using Tdbcombobox compounding

Asked

Viewed 483 times

0

I have the following problem, when I select an item in Tdbcombobox when leaving the component it automatically selects the last record.

DM_BancoInsumos.IBQCons_ForneInsumos.Close;
DM_BancoInsumos.IBQCons_ForneInsumos.Open;
DBComboFornecedor.Items.Clear;
DBComboFornecedor.Items.Add('Selecione');
while DM_BancoInsumos.IBQCons_ForneInsumos.Eof = False do
begin
  DBComboFornecedor.Items.Add(DM_BancoInsumos.IBQCons_ForneInsumosCodFornecedor.Text);
  DM_BancoInsumos.IBQCons_ForneInsumos.Next;
end;

In the compound Tdbcombobox:

Style -> csDropDownList
DataSource -> Ds_ConsForncedores
DataFiel -> CodFornecedor

At Datasource

DataSet -> DM_BancoInsumos.IBQCons_ForneInsumos
  • The problem is that you must have put in the component’s Onchange/Onexit event, with this each time you select one it activates the event and stops at the last, does the search only once and then it will work.

  • @Jeffersonrudolf put this code in the form’s Onactive, at the Onchange/Onexit events I have no code.

1 answer

0

Good night Tiago
By the code you posted the problem of the combobox appearing the last record is because you made a while not eof.
So when it comes to the end in the while it’s the last region that’s on the combo.
If you want the first ADD you made (SELECT) to appear just put the "end" of while Dbcombofornecedor.itemindex:=0;

while DM_BancoInsumos.IBQCons_ForneInsumos.Eof = False do
begin
  DBComboFornecedor.Items.Add(DM_BancoInsumos.IBQCons_ForneInsumosCodFornecedor.Text);
  DM_BancoInsumos.IBQCons_ForneInsumos.Next;
end;

DBComboFornecedor.itemindex:=0;

I hope I’ve understood your problem :)

  • I do this Ricardo, the "Select" appears set in Tdbcombobox, the question comes when I select a value of Tdbcombobox, when leaving the component it loses this value automatically going to the last value of Tdbcombobox.

  • Good afternoon @Tiago Casanova. In which event is this code you posted?? Type in Dbcombobox ONEXIT, form ONCREATE etc..

  • You are at the event Onactive do Form @Ricardo M. Souza

  • @Tiago Casanova Cara.. if you want to send me the form with the table script I can take a look here.

  • @Iago Casanova A curiosity. If the datasource is linked in the query and dblookyp is linked in the datasource and field you DO NOT need to add the fields in the lookup they will automatically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.