PDA

View Full Version : Help Please : TDBLookupListbox Question ?


FancyFace
07-12-2001, 09:58 PM
Hi All,

I have a TDBLookupListbox that I would like to have filled at runtim. Actually, I have a button on a form and when the button is clicked,it should fill the TDBLookuplistbox with the lookup values. If I set the ListSource, ListField and Keyfield at design time it works fine. The code I use at runtime is :

lookuplistbox.listsource := SourceName;
lookuplistbox.listfield := DataModule.TableName.FIELDBYNAME('field name').AsString;
lookuplistbox.Keyfield := DataModule.TableName.FIELDBYNAME('field name').AsString;

Say for instance the first value of the fieldname is RWI,
the error would be: lookuplistbox: Field 'RWI' not found

I don't know what is wrong, Any help will be appreciated !
By the way, I use Delphi 4.

Thanks
Christiaan

osamaao
07-13-2001, 12:17 PM
Hi, you should assign to the keyField and the listField the Field name and not the Field value, the correct source is:

lookuplistbox.listsource := SourceName;
lookuplistbox.listfield := 'field name1';
lookuplistbox.Keyfield := 'field name2';

for example:

lookuplistbox.listfield := 'Name';
lookuplistbox.Keyfield := 'Code_No';

hope this will help.