Subject Re: [IBO] Grid and LookupCombo
Author Geoff Worboys
> 1. There are 2 tables: A - People, B - Departments
> A: PID, DEPID, NAME.....PID - primary key
> B: DID, DEPNAME, ..... DID - primary key
> A.DEPID -> FK from B.DID
>
> 2. Need to edit A in grid with LookupCombo for DEPID.
> Grid with columns like: NAME, DEPARTMENT, ...... so DEPARTMENT
> column must show B.DEPNAME, LookupCombo must show list of
> B.DEPNAME but when I post edits - I need to set A.DEPID with
> value from B.DID.

Unless I misunderstand, thats what exactly what lookupcombos are
designed to do. There are sample applications that show this.

You need two datasets. One is the main/grid dataset which requires an
embedded select or join so that the department name is available for
all grid rows. The second dataset is a lookup dataset used with the
LookupCombo for selection of entries from the department list. The
most important properties are...

Main/Grid Dataset....

SQL =
SELECT PID, DEPID,
(SELECT DEPNAME FROM B
WHERE B.DID=A.DEPID) AS DEPARTMENT,
NAME, <etc>
FROM A
FOR UPDATE

KeyLinks =
PID


Lookup Dataset...

SQL =
SELECT DID, DEPNAME
FROM B

OrderingItems
Name=DEPNAME
OrderingLinks
DEPNAME=1
OrderingItemNo = 1

KeySource = MainDataset_DataSource

KeyLinks =
DID=DEPID

KeyDescLinks
DEPNAME=DEPARTMENT


The embedded select in the main dataset ensures that the Department
name value is available for display in the grid even when the lookup
combo is not displayed (since it is only displayed when editing the
particular cell and row.

The KeyDescLinks tell the lookup dataset to update the DEPARTMENT
computed column of the main dataset (from the DEPNAME column of the
lookup) at the same time that it updates the foreign key value defined
in KeyLinks. That way the newly selected name is available for
display even when you tab away from the lookupcombo (otherwise the
embedded select value would be updated until the row is posted and
refreshed).

You will notice that it is the lookup dataset that does the work. All
the lookupcombo control does is allow you to scroll the lookup
dataset. As the lookup dataset scrolls it uses its KeyLinks and
KeyDescLinks properties to sync the main dataset with the selection.


HTH

Geoff Worboys
Telesis Computing