INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Database Programming

How to use a look up field in a DBGrid by svanels
Posted: 27 Oct 01 (Edited 1 Jul 03)

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

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close