Delphi - DBGrid - dynamically add combo lookup field

510 views Asked by At

Try add lookup field in DBGrid.

its code work well: its standart adding lookup using external data for lookup filling

p_StoredProc.FieldDefs.Update;

for i := 0 to p_StoredProc.FieldDefs.Count - 1 do
p_StoredProc.FieldDefs.Items[i].CreateField(p_StoredProc);

with TStringField.Create(p_StoredProc) do
  begin
    FieldName := 'MReasonID';
    FieldKind:= fkLookup;
    DataSet := p_StoredProc;
    name := Dataset.name + FieldName;
    KeyFields:= 'ReasonID';
    LookUpDataset:= dm_ADOStoredProc.p_fin_Reason;
    LookUpKeyFields:= 'ReasonID';
    LookUpResultField:= 'Name_';
    p_StoredProc.FieldDefs.Add(name, ftString, 80, false);
  end;

but add this code and this part not work - empty lookup. its try using only cached values.

with TStringField.Create(p_StoredProc) do
  begin
    FieldName := 'MDateTypeID';
    FieldKind:= fkLookup;
    DataSet := p_StoredProc;
    name := Dataset.name + FieldName;
    KeyFields:= 'DateTypeID';


    Lookup := True;
    LookupCache := True;

    LookupList.Add(0,'');
    LookupList.Add(1,'ATA(B)');
    LookupList.Add(2,'Delivery Unloading');
    LookupList.Add(3,'Invoice Date');
    LookupList.Add(4,'Sales Date');

    p_StoredProc.FieldDefs.Add(name, ftString, 40, false);

    RefreshLookupList;

  end;

Whats wrong? Thank you.

postreply: deleting RefreshLookupList do not any changes

0

There are 0 answers