Subject Re: [IBO] TIB_ComboBox / TIB_LookupCombo
Author Paul Vinkenoog
Hello Rainer,

> CREATE TABLE TLSR_LINE_STOP_REASON (
> LSR_ID INTEGER NOT NULL,
> LSR_REGION CHAR(80),
> LSR_REASON_TEXT CHAR(255)
> );

> CREATE TABLE TLS_LINE_STOP (
> LS_ID INTEGER NOT NULL,
> LS_START_DATE_TIME TIMESTAMP,
> LS_END_DATE_TIME TIMESTAMP,
> LS_LSR_ID INTEGER
> );
>
> Where LS_LSR_ID is a foreign key referencing LSR_ID.
>
> What would be the best way to let a user select a
> TLSR_LINE_STOP_REASON for the TABLE TLS_LINE_STOP?
>
> A combobox with TLSR_LINE_STOP_REASON.LSR_REASON_TEXT as the Items
> with the selected LSR_ID beeing placed into TABLE
> TLS_LINE_STOP.LS_LSR_ID would be great, but how can I achieve this?

This is a classic case of a KeySource-Lookup relation. You set it up
like this:

- Set up an IB_Query QryLineStop on table TLS_LINE_STOP, but include
lsr_reason_text also, either by a subselect or by a join.
(If you use a join, you must set QryLineStop.KeyRelation to
TLS_LINE_STOP or the query won't be updateable.)

- Set up another query QryLineStopReasonLU with this SQL:
select lsr_id, lsr_reason_text from tlsr_line_stop_reason
order by lsr_reason_text // not necessary, but nice for the user

- Set QryLineStopReasonLU.KeySource to the DataSource of QryLineStop.

- Set QryLineStopReasonLU.KeyLinks to:
lsr_id=tls_line_stop.ls_lsr.id

- Set QryLineStopReasonLU.KeyDescLinks to:
lsr_reason_text=reason
( for "reason", you take the name that the joined or subselected
column has in QryLineStop.SQL ! )

- Preferably make lsr_id invisible in QryLineStopReasonLU.

- Drop an IB_LookupCombo on your form. Set its DataSource to the
DataSource of QryLineStopReasonLU. Set its DisplayField to
lsr_reason_txt.

Now everything works automagically after preparing and opening the
queries. Even better: instead of just somewhere on the form, you can
drop the IB_LookupCombo right on the grid connected to QryLineStop (if
you have one). Don't worry about how it looks at design time. At
runtime, the LookupCombo will be hidden until the user selects a cell
in the "reason text" column. Then the combo will align itself to the
cell, become visible and allow the user to select a reason.


Greetings,
Paul Vinkenoog