Lookupfields in grid.. Disappear and reappear :S

From: Arnoud van Bers (avbers_at_)
Date: 04/20/04


Date: Tue, 20 Apr 2004 11:44:30 +0200

Hi There,

I suffer from a vague problem:
For lookupfields in a dbgrid I use a (parameterised) query, which executes
fine but doesn't always show up in a grid...

When opening the grid, I see the following (NOT CORRECT)
Watch the first column:

http://web10.ontwikkeling.ica.han.nl/1.gif

After scrolling to the end and to the beginning again, I get the following
result (CORRECT)

http://web10.ontwikkeling.ica.han.nl/2.gif

Suddenly all records are visible..
At first I thought it would be a repaint or doublebuffering problem.. this
is not the case!

Code:

myFKQuery := TADOQuery.Create(myGrid);
with myFKQuery do
begin
Connection := DataMod.DBConn;
DataSource := myGrid.Datasource;
(Can this be a problem? It is absolutely necessary)
CacheSize := 30;
SQL.Text := DataMod.cdsColumns.Fields[24].AsString;
end;

with TStringField.Create(mySP) do
begin
ReadOnly := TRUE;
mySP.Fields[k].Visible := FALSE;
FieldName := myGrid.DataSource.DataSet.Fields[k].FieldName+'_';
FieldKind:= fkLookup;
DataSet := mySP;
if DataMod.cdsColumns.Fields[2].AsString <> '' then DisplayLabel :=
DataMod.cdsColumns.Fields[2].AsString;
Name := FieldName;
KeyFields:= mySP.Fields[k].FieldName;
ReadOnly := TRUE;
Size := 300;
LookUpDataset:= myFKQuery
LookUpKeyFields:= DataMod.cdsColumns.Fields[22].AsString;
LookUpResultField:= mySL.Strings[0];
mySP.FieldDefs.Add(Name, ftString, 300, false);

The query is a parameterised query:

SELECT OPLSAMENSTEL.* FROM OPLSAMENSTEL,MODULE B WHERE
OPLSAMENSTEL.MODULEOPL=B.CODEMODULE and OPLEIDING = :OPLEIDING

Can somebody explain this to me? (and have a solution?? :P)

Greetz,
Arnoud van Bers

The Netherlands