Using TDBLookupCombo correctly? lazarus / 16-Databases ---------------------------------------------------------------------- bill0287 · 2013-12-01 06:28 I have just found Lazarus after being out of Delphi for many years. I need to update an old app and I am having trouble translating some code. I have a TDBLookupComboBox looking up a field value in a "look up" table (Dbf). I need to go to that record and then take two other field values from that record and apply them to DBEDit fields attached to a second database. I don't know how to get the lookup table to set to the right record based on the combo's value? I don't know how to capture the two other fields and apply them to the second database via the dbedits so that it updates the table? In Delphi I had something like this, but can't seem to figure out how to do this in Laz: Code: [Select]  //Use dblookupcombo to find name in data.dbf   Table3.SetKey;   Table3.FieldbyName('NAME').AsString := DBLookupComboBox.Text;   Table3.GotoKey;   //Table1.Edit;   DBEdit1.Text := Table3.FieldbyName('A').AsString;   DBEdit2.Text := Table3.FieldbyName('B').AsString; Any help would be appreciated ---------------------------------------------------------------------- BigChimp · 2013-12-01 09:17 Not a GUI guy at all, but: could you use the ListSource to get the lookup datasource and from there get the field contents? http://wiki.lazarus.freepascal.org/dblookupcombobox combined with http://lazarus- ccr.sourceforge.net/docs/lcl/dbctrls/tdblookupcombobox.html Alternatively, apparently this control http://wiki.lazarus.freepascal.org/dblookupcombobox#Alternative_contro l allows displaying multiple fields in the lookup table. Perhaps you can set their column widths to 0, hiding them, but still making the values available for retrieval. Hope somebody who actually knows what he's doing/has done this before will step in - and ideally update that tdblookupcombobox wiki page ---------------------------------------------------------------------- mangakissa · 2013-12-01 09:26 Setkey is only working with an index. Use locate to find your record. Code: [Select]if Table3.locate('name',vararrayof([DBLookupComboBox.Text]),[]) then begin   DBEdit1.Text := Table3.FieldbyName('A').AsString;   DBEdit2.Text := Table3.FieldbyName('B').AsString; end; ---------------------------------------------------------------------- bill0287 · 2013-12-01 16:36 Thanks. I was able to use locate to find and copy the records I needed. I noticed one other issue: I need the found value of the DBLookupCombo box to be written to the database, which it was, but when I run the program again, the DBLookupCombo box field is blank and not showing the value I selected (but the data is in the table). I have it set up like this: note that the lookup DB and the target DB are the same actual table but with different datasource/dbf components. DBLookupComboBox: ListSource = LookupDatasource DataSet = LookupDataset ListField and Keyfield = Name DataSource = the primary Datasource DataField = the target field for the lookup value I guess my question is why does the DBLookupCombo box not display the value found in it's Datafield? Maybe I am doing this wrong ---------------------------------------------------------------------- mangakissa · 2013-12-02 12:47 You can't use a dataset twice for lookup and data. That's looking for trouble and isn't the right way. A lookuptable is a dataset from another table with the key of the requested field kan be found. Just copy your fields to a memdataset if you want to use the primary dataset. lookupdataset = memtable