Subject Re: [IBO] Lookup Doesn't work properly
Author Helen Borrie
At 05:37 AM 5/07/2005 +0000, you wrote:
>I have a problem with a lookup combo that does not select the current
>value of a record.
>
>The select statement of the data file is:
>SELECT PROVART.PROV
> , PROVART.CVEART
> , INVE01.DESCR AS NOMPROD
>FROM PROVART
>JOIN INVE01 ON PROVART.CVEART=INVE01.CLV_ART
>
>The keylinks of this query is:
>PROVART.PROV
>PROVART.CVEART
>
>The select statement of the lookup table (Art) is:
>SELECT CLV_ART, DESCR
>FROM INVE01
>
>The keylinks of the lookup table is:
>INVE01.CLV_ART=PROVART.CVEART
>
>The KeyDescLinks is:
>INVE01.DESCR=PROVART.NOMPROD
>
>The KeySource is: dProvArt
>
>I have a TIB_Grid of the provart table with a TIB_LookupCombo in it
>called cbArt with the following properties:
>DataSource = dArt
>DisplayField = DESCR
>CustomPopUp = grdArt
>
>The behaviour Ia am getting is the following:
>
>1) the PROVART grid display the code CVEART and the description
>NOMPROD correctly.
>2) When I click on the NOMPROD field on the grid, the lookup (arrow)
>button appears and the field contents become <blank>, (blue) no text.
>3) I click on the arrow button and a grid of the lookup table appears
>with the values of the code (CLV_ART) and the description (DESCR),
>but at the beginning of the table and not at the current value of the
>PROVART table.
>
>I have dedicated HOURS at this and cannot get it to work right. What
>am I doing wrong?

Where you are going astray here is with the use of the join, which produces
an non-editable set. Use a subquery instead :

SELECT
p.PROV,
p.CVEART,
(SELECT i.DESCR FROM INVE01 i
WHERE I.CLV_ART = p.CVEART) AS NOMPROD
FROM PROVART p


>> The keylinks of this query is:
PROVART.PROV
PROVART.CVEART

That will be OK provided the combination of PROV and CVEART is unique.

>> The select statement of the lookup table (Art) is:
SELECT CLV_ART, DESCR
FROM INVE01

OK

>> The keylinks of the lookup table is:
INVE01.CLV_ART=PROVART.CVEART

OK

>> The KeyDescLinks is:
INVE01.DESCR=PROVART.NOMPROD

No. You can't refer to a virtual field like it was a real database
field. KeyLinks will need to be:
DESCR=NOMPROD

>> The KeySource is: dProvArt

The KeySource should be the tib_datasource that is being pointed to by the
KeySource dataset.

So, as far as I can see, it's really just a couple of small mistakes:

1) trying to use a non-editable set for what is purely an editing operation
and
2) trying to link a virtual field to a database field.

>> Another quirk is that the first time that I open the lookup grid, it
appears very narrow. If I close it and open it again, it appears with
the correct width but still not at the value of the data.

In IBO, data drives controls, not the other way around. Set your grid
fields (i.e. the column(s) visible in the drop-down portion) using
FieldsDisplayWidth; however, you can set the physical width of the editbox
part of the control (which is not a grid) using the Width property.

Helen