Lookup combo with filter

I'm using xe10 and the latest vcl but I'm not sure how to implement the following:


Using a TDBAdvGrid, the data source contains a lookup field to display the text.  This works fine, but I'd like to change the filter of the lookup table depending on the row selected and when the drop down is displayed to only show those items that were filtered.  When the combo is closed up, the filter is removed.  


What I'm seeing:
When another col is selected on the same row, some of other the rows that have the lookup are cleared visually.

I'm clearly missing something but not sure what.  The question is what is the preferred way to implement a lookup field (and drop down list) where a filter is different for each row?

Can you please provide some more details how exactly you change the filter, when you update the filter. I guess that updating the filter means changing the query for the lookup control listsource?

Hi,

I am changing the filter on query for the lookup control on the onCanEditCell event.  When Col2 is entered, the drop down correctly shows the items.  When the combo closes up, the correct item still shows.  While on the same grid row, if col3 is clicked, the display in the look up fields of col2 on other rows BLANK (as if the filter were still applied).


 dm.adsPanel.Filtered := False;
  try
  if ACol = 2 then
    begin
      dm.adsPanel.Filter := 'InstrumentTypeId = ' + memWorklistPanel.FieldByName('InstrumentPanelTypeId').AsString;
      dm.adsPanel.Filtered := True;
    end;
  except
  on e : Exception do
    dm.adsPanel.Filtered := False;

  end;

I would recommend to do this filter operation only from the OnGetEditorProp event as OnCanEditCell is also triggered to know if a cell control should be displayed in grayed state.
Applying a filter in OnGetEditorProp can be done for example in our demo ADOLookup with:


procedure TForm1.DBAdvGrid1GetEditorProp(Sender: TObject; ACol, ARow: Integer;
  AEditLink: TEditLink);
begin
  if odd(arow)  then
  begin
    adotable2.Filtered := false;
    adotable2.Filter := 'COUNTRY LIKE ''S%''';
    adotable2.Filtered := true;
  end
  else
  begin
    adotable2.Filtered := false;
  end;
end;