Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use a look up field in a DBGrid

Database Programming

How to use a look up field in a DBGrid

by  svanels  Posted    (Edited  )
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.

Check out also: faq102-1212
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top