|
|
 |
 |
|
Join the Discussion
|
"Post your views and comments to this chapter of the free Delphi database Programming Course"
Discuss!
|
|
 |
 |
|
|
 |
 |
 |
New ... lookup field
To crete a new field object you have to invoke the Fields editor for a dataset. Double click the ApplicationsTable and right click it to have a pop up menu displayed. Pick "New field..."
The idea is to set the value for the Author field by picking it's email. I know this does not make much sense, but it will bring the lookup idea closer. In the New field form fill the boxes as on the picture below. We create a new AEmail field for the ApplicationTable dataset. As you can see from the picture, there are few very important properties you have to understand prior to working with lookup fields.
.Field Name is the name of the lookup field. Set it to AEmail.
.Dataset identifies the dataset that contains lookup values (Authors).
.KeyFields is a field in the Applications dataset we are setting through a lookup.
.Lookup Keys is a field in the lookup dataset (Authors) to match against the KeyFields.
.ResultField is a field in the lookup dataset to return as the value of the lookup field you are creating.
That's it. No code required. Start your project (or set Active property for both tables to True) and you can see that DBGrid, in the AName fields column, has a combo box with author emails. As you pick an email the corresponding author field changes. We are looking up an authors email to change the author. Note that AEMail is a read-only field.
Note: the combo box in the cell of a DBGrid has nothing with the PickList property of Grid's column. This will be explained later in this chapter.
Next page > The DBLookupComboBox looks up > Page 1, 2, 3, 4
DB Course Next Chapter >> >>
Compacting an Access database with ADO and Delphi - DB/16
|