The DBGrid component does not have look-up capabilities unless this is defined in the Data Access component it is linked too.
So the bottom line of this is modifying your TTable or TQuery which supply the data
Place on a form:
a) a TDatase
properties: AliasName = DBDEMOS, Connected = True, DatabaseName = myDATA
b) a TTable (table1)//this is the main table
properties: DatabaseName = myDATA, TableName = orders.db, Active = true
c) a TTable (table2)//this is the lookup table
properties: DatabaseName = myDATA, TableName = employee.db, Active = true
d) a TDatasource
properties: Dataset = table1 (The Main table)
Now we are going to add the name of the employee to Table1, the original table (orders.db) is not altered
e) open the field editor for table1
add orderno, empno, etc.
f) add a new field:
Properties:
name it emp_name
type = string
field type = look-up
key fields = empno the look-up part
look up keys = empno
dataset = table2
result field = LastName
g) add a dbgrid or dbctrlgrid
properties: DataSource = DataSource1 (you will see now some data, if the table is active)
h) Open the columneditor and add:
orderno, emp_name etc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.