Example 2: TcxDataSummaryItems.OnSummary
- 2 minutes to read
A summary calculation involves iteration of item elements within a group and evaluation of a specific number (the number of item elements, sum, the maximum value etc.). It is possible to substitute an element value when calculating a summary.
Let us suppose that you have a table which represents information on the country population and area. To calculate the maximum density of population within a group of records you can use a summary of the skMax type and write the TcxDataSummaryItems.OnSummary event as follows. See the Creating Summaries topic regarding how to set summaries for a grid control.
procedure TForm1.cxGrid1DBTableView1TcxGridDBDataControllerTcxDataSummary
DefaultGroupSummaryItemsSummary(
ASender: TcxDataSummaryItems; Arguments: TcxSummaryEventArguments;
var OutArguments: TcxSummaryEventOutArguments);
var
AArea, APopulation: Extended;
begin
//Locate a value in the specific record for Area item
AArea := ASender.DataController.Values[Arguments.RecordIndex, DBTableView1Area.Index];
//Locate a value in the specific record for Population item
APopulation := ASender.DataController.Values[Arguments.RecordIndex, DBTableView1Population.Index];
//Set population density to Value
OutArguments.Value := APopulation / AArea;
end;