Search code examples
delphidelphi-7ado

Delphi 7 ADO, DBGrid combobox field


I have these tables in my MySQL database:

enter image description here

I want to display the employee table and job.jobName in DBGrid and allow user to edit it (using DBNavigator maybe).

So I created an ADOQuery with SELECT ... JOIN query, a DataSource and linked a DBGrid DataSource to it. enter image description here

Everything works, but instead of jobId field I want Job field which displays JobNames, allows to choose it via combobox and sets id in the employee.JobId. Something like this: enter image description here

I thought that I can achieve it using LookupKeyFields/LookupResultFields properties for JobId field in ADOQuery but in fact it doesn't work for me.

I added an ADOTable which just loads everything from the job table and set JobId field (in ADOQuery) properties: FieldKind = fkLookup, KeyFields = JobId, LookupDataSet = tblJob, LookupKeyFields = IdJob, LookupResultFields = JobName.

enter image description here

But now Job column is just empty and without comboboxes.

Also I found PickList property in DBGrid columns, but it is TStrings, so it allows only displayed string, not separate displayed strings and values. And it did nothing even when I tried to fill it for string field (LastName).


Solution

  • Right click on your qryEmployes dataset, choose new field ans assign needed values.

    Sorry for german version