Главная страница | назад





Article #19652: Creating a lookup field in a TDBGrid for Builder

 Question and Answer Database
FAQ: FAQ4652C — Creating a lookup field in a TDBGrid for Builder
Category: Database Issues
Platform: All Windows
Product: All-CBuilder,
Question:
How do I create a lookup field in a TDBGrid in C++ Builder
Answer:
1. Drop 2-TTable's, 1-TDataSource and 1-TDBGrid on a form.
2. Connect Table1 to DataSource1 to DBGrid1: In the object inspecter, set these attributes.
a. DataSource1.DataSet = Table1
b. DBGrid1.DataSource = DataSource1
3. Setup Table1: In the object inspecter for Table1, set these attributes.
a. DatabaseName = BCDEMOS
b. TableName = Customer
c. Active = True
4. Setup Table2: In the object inspecter for Table2, set these attributes.
a. DatabaseName = BCDEMOS
b. TableName = Orders
c. 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 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: CustOrder
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
8/4/99 11:54:12 AM

Last Modified: 01-SEP-99