TcxDataSummaryItems.Add Method
Creates a summary item with the default settings and adds it to the collection.
#Declaration
Delphi
function Add: TcxDataSummaryItem; overload;
#Returns
Type | Description |
---|---|
Tcx |
The created summary item. |
#Remarks
Call the Add
function to create a summary item with the default settings. You can use the Items property to access all summary items in the collection.
#Code Example: Create and Display Three Footer Summaries
The code example in this section creates and displays three summary items for the same column. These items use three different predefined summary calculation algorithms – SUM, MAX, and MIN.
How to Test this Code Example
Follow the steps below to test this code example in your RAD Studio IDE:
- Copy the DFM code snippet below.
- Create a new project in the IDE and focus an empty form.
- Press Ctrl+V to populate the form with preconfigured components.
- Select the form and create an empty OnCreate event handler, paste the code example, and run the project.
object cxGrid1: TcxGrid
Left = 72
Top = 80
Width = 425
Height = 321
TabOrder = 0
object cxGrid1DBTableView1: TcxGridDBTableView
Navigator.Buttons.CustomButtons = <>
ScrollbarAnnotations.CustomAnnotations = <>
DataController.DataSource = DataSource1
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
object cxGrid1DBTableView1RecId: TcxGridDBColumn
DataBinding.FieldName = 'RecId'
Visible = False
end
object cxGrid1DBTableView1Groups: TcxGridDBColumn
DataBinding.FieldName = 'Groups'
end
object cxGrid1DBTableView1Names: TcxGridDBColumn
DataBinding.FieldName = 'Names'
end
object cxGrid1DBTableView1Values: TcxGridDBColumn
DataBinding.FieldName = 'Values'
Width = 175
end
end
object cxGrid1Level1: TcxGridLevel
GridView = cxGrid1DBTableView1
end
end
object dxMemData1: TdxMemData
Active = True
Indexes = <>
Persistent.Data = {
5665728FC2F5285C8FFE3F04000000140000000100070047726F757073001400
0000010006004E616D657300040000000300070056616C756573000400000009
000600446174657300010600000047726F75703101050000004E616D6531010A
000000017B000B00010600000047726F75703101050000004E616D6532011400
000001CF0E0B00010600000047726F75703201050000004E616D6533011E0000
00017A210B00010600000047726F75703201050000004E616D65340128000000
01892B0B00}
SortOptions = []
Left = 248
Top = 336
object dxMemData1Groups: TStringField
FieldName = 'Groups'
end
object dxMemData1Names: TStringField
FieldName = 'Names'
end
object dxMemData1Values: TIntegerField
FieldName = 'Values'
end
object dxMemData1Dates: TDateField
FieldName = 'Dates'
end
end
object DataSource1: TDataSource
DataSet = dxMemData1
Left = 152
Top = 320
end
object dxSkinController1: TdxSkinController
SkinName = 'WXICompact'
SkinPaletteName = 'Office Dark Gray'
Left = 64
Top = 320
end
procedure TMyForm.FormCreate(Sender: TObject);
var
ASummary: TcxDataSummary;
ASummaryItem: TcxGridDBTableSummaryItem;
begin
cxGrid1DBTableView1.OptionsView.Footer := True; // Displays a footer
cxGrid1DBTableView1.OptionsView.FooterMultiSummaries := True; // Allows the footer to fit all summaries
ASummary := cxGrid1DBTableView1.DataController.Summary;
ASummary.BeginUpdate; // Initiates the following batch change
try
// Create three summary items
ASummaryItem := ASummary.FooterSummaryItems.Add as TcxGridDBTableSummaryItem;
ASummaryItem.Column := cxGrid1DBTableView1Values; // Associates the summary with the "Values" column
ASummaryItem.Kind := skSum; // Sums all values in the target column
ASummaryItem := ASummary.FooterSummaryItems.Add as TcxGridDBTableSummaryItem;
ASummaryItem.Column := cxGrid1DBTableView1Values; // Associates the summary with the "Values" column
ASummaryItem.Kind := skMax; // Displays the highest value in the target column
ASummaryItem := ASummary.FooterSummaryItems.Add as TcxGridDBTableSummaryItem;
ASummaryItem.Column := cxGrid1DBTableView1Values; // Associates the summary with the "Values" column
ASummaryItem.Kind := skMin; // Displays the minimum value in the target column
finally
ASummary.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
end;
end;
See Also