How to show the data related to an ID instead of the ID?

463 Views Asked by At

In summary, I have a database (Access) with 4 related tables, as seen in the picture:

image

In Delphi, I have a TDBGrid that shows the data from the "resultas" table (using TADOTable), as seen here:

image

As you can see, the field for the test id shows numbers (id of the test). What I want is to show the test name instead of that number. Or, can I add a field (in Delphi) that shows the name of the test related to the id (a calculated field, maybe)?

2

There are 2 best solutions below

3
Miroslav Penchev On BEST ANSWER

You need Lookup field defined in TADOTable component which is responsible for "Resultas" table. Defining a Lookup Field

Keep in mind that big datasets could result to poor performance. The correct way is to use SELECTs with JOINs in TADOQuery.

2
Remy Lebeau On

TDBGrid has an OnDrawColumnCell event. You can custom-drawn any cell to look however you want.

Or, you could simply access the TADOTable's TField object for the ID_Test field, and assign a handler to its OnGetText event to return the TField.DisplayText value of the table's Nom_Test field.