Example: TcxDBDataModeController.OnDetailFirst
The TcxDBDataModeController.OnDetailFirst event handler is listed in the next example. It does not reopen the underlying query if it already contains the required data (the query parameter value is the same as the value of the detail key field name passed via the AMasterDetailKeyValues argument). In this case the current record is only positioned to the first record in the query dataset.
Otherwise the query with a new parameter value is reopened by setting the Active property to True. The AReopened parameter is set to True in this case.
procedure TForm1.DBTableView1DataControllerDataModeControllerDetailFirst(
Sender: TcxDBDataModeController; ADataSet: TDataSet;
const AMasterDetailKeyFieldNames: String;
const AMasterDetailKeyValues: Variant; var AReopened: Boolean);
begin
with (ADataSet as TQuery) do
begin
if ParamByName('CustNo').Value = AMasterDetailKeyValues then
begin
First;
Exit;
end;
DisableControls;
try
Active := False;
ParamByName(AMasterDetailKeyFieldNames).Value := AMasterDetailKeyValues;
Active := True;
finally
EnableControls;
end;
AReopened := True;
end;
end;