I could see in source code that TTMSFNCDataGrid has support to lookup fields using comboboxes, but I used lookupfields through a DataGridDatabaseAdapter, and nothing special was done.
What are the steps needed to activate lookup comboboxes in DataGrid ?
If I simply place a string LookUp Field in Adapter / Grid, it shows the correct text in the corresponding cell, but opens an empty combobox at runtime.
That's why I asked about the steps to activate it. Seems not to be so out of the box
Doesn't work with TAureliusDataset because TAureliusDataset does not override TDataSet virtual method GetClonedDataset.
TTMSFNCDataGridDatabaseAdapter uses GetClonedDataSet to fill the lookup column combobox.
if Assigned(AField) and Assigned(AField.LookupDataSet) then
begin
{$HINTS OFF}
{$IF COMPILERVERSION > 31}
ds := AField.LookupDataSet.GetClonedDataSet(True);
{$ELSE}
ds := nil;
{$IFEND}
{$HINTS ON}
if Assigned(ds) then
begin
try
ds.First;
...
...
finally
ds.Free;
end;
end;
Commenting those things ( GetClonedDataSet and ds.Free ) did the job .
if Assigned(AField) and Assigned(AField.LookupDataSet) then
begin
{$HINTS OFF}
{$IF COMPILERVERSION > 31}
ds := AField.LookupDataSet {.GetClonedDataSet(True)} ;
{$ELSE}
ds := nil;
{$IFEND}
{$HINTS ON}
if Assigned(ds) then
begin
try
ds.First;
...
...
finally
// ds.Free;
end;
end;
BTW, this is the root TDataSet.GetClonedDataSet , with no overriding method:
function TDataSet.GetClonedDataSet(WithSettings: Boolean): TDataSet;
begin
Result := nil;
end;
TClientDataSet overrides it (via it's parent class TCustomClientDataSet):
function TCustomClientDataSet.GetClonedDataSet(WithSettings: Boolean): TDataSet;
begin
Result := NestedDataSetClass.Create(nil);
try
(Result as TCustomClientDataSet).CloneCursor(Self, False, not WithSettings);
except
Result.Free;
raise;
end;
end;
Then unfortunately this is a shortcoming in TAureliusDataset, the cloned dataset is required because otherwise it will apply filter & distinct values directly on the dataset. Actually, TAureliusDataSet also does not support built-in filtering, you have to implement the OnFilterRecord event. We'll look into this.
I'm just talking about the lookup column combobox filling. There's no filtering there. It's about the TTMSFNCCustomDataGridDatabaseAdapter.LoadLookupList method, in unit unit VCL.TMSFNCDataGridDatabaseAdapter.pas .
By the way, LoadLookupList and GetFilterData are the only methods (TTMSFNCDataGrid related) that call GetClonedDataSet.
Even FNCGrid has similar methods, but does not call GetClonedDataSet.
None of them apply anything on the cloned dataset.
They apply DisableControls/EnableControl on the original datasets.
GetFilterData also modifies the original DataSet's Filtered property, and then restore the original value.
Both of these methods currently just use the cloned dataset to make a while-not-eof loop and read content. (talking about current VCL flavour. I didn't check other platforms, neither know what's planned for future versions);
Yes, we saw issues with that when we directly did the while not EOF loop on the dataset. When a component is assigned, this would visually jump through the rows even though we had DisableControls / EnableControls.
Either way, I implemented a fallback mechanism, if the cloning does not return a valid instance, the original dataset is used. Next version will have this improved.
So the behavior will be identical to that of TTMSFNCGrid, when there is no cloning available.