- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


3096:How to Create a TDBGrid Lookup Field in Delphi 2.0

KEYWORDS: TDBGrid Database Lookup Fields AREA: Database Programming

How to create a lookup field in a TDBGrid for Delphi 2.0


1. Drop 2-TTable's, 1-TDataSource and 1-TDBGrid on a form.

2. Connect Table1 to DataSource1 to DBGrid1
   a. DataSource1.DataSet = Table1
   b. DBGrid1.DataSource = DataSource1

3. Setup Table1
   a. Table1.Database = DBDemos
   b. Table1.TableName = Customer
   c. Table1.Active = True

4. Setup Table2
   a. Table2.Database = DBDemos
   b. Table2.TableName = Orders
   c. Table2.Active = True

5. Add all of the fields for Table1 by bringing up the Fields Editor:
   a. Double click on Table1
   b. Right click on Fields Editor
   c. Add New Fields. Add all of them

6. Add a new field for Table1.
   a. Right click on Fields Editor, and select New Field.

7. Specify the following parameters for the newly added field.
   a. Name: Bob
   b. Type: String
   c. Size: 30
   d. Select Lookup
   e. Key Fields: CustNo    -  Field in Table1 to store value
   f. DataSet: Table2       -  Table lookup is being done on
   g: LookUpKeys: CustNo    -  This Key gets copied to KeyField
   h: Result Field: OrderNo -  Value to display to the user in the
                            drop down box

8. Run the application

        TI



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile