Back to Devexpress

GridSummaryItem.SummaryType Property

windowsforms-devexpress-dot-xtragrid-dot-gridsummaryitem.md

latest8.1 KB
Original Source

GridSummaryItem.SummaryType Property

Gets or sets the aggregation function type.

Namespace : DevExpress.XtraGrid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(SummaryItemType.None)]
[DXCategory("Behavior")]
[XtraSerializableProperty(1)]
public SummaryItemType SummaryType { get; set; }
vb
<DefaultValue(SummaryItemType.None)>
<XtraSerializableProperty(1)>
<DXCategory("Behavior")>
Public Property SummaryType As SummaryItemType

Property Value

TypeDefaultDescription
SummaryItemTypeNone

A SummaryItemType enumeration value specifying the summary type.

|

Available values:

NameDescription
Sum

The sum of all values in a column.

| | Min |

The minimum value in a column.

| | Max |

The maximum value in a column.

| | Count |

The record count.

| | Average |

The average value of a column.

| | Custom |

Specifies whether calculations should be performed manually using a specially designed event.

| | None |

Disables summary value calculation.

|

Remarks

Use the SummaryType property to specify the type of aggregate function used to calculate the summary value. The following predefined aggregate functions are available:

  • sum;

  • minimum value;

  • maximum value;

  • average value;

  • the number of records.

  • C#

  • VB.NET

csharp
using DevExpress.XtraGrid;

gridView1.OptionsView.ShowFooter = true;

GridColumnSummaryItem siTotal = new GridColumnSummaryItem();
siTotal.SummaryType = SummaryItemType.Count;
siTotal.DisplayFormat = "{0} records";
colOrderID.Summary.Add(siTotal);

GridColumnSummaryItem siAverage = new GridColumnSummaryItem();
siAverage.SummaryType = SummaryItemType.Average;
siAverage.FieldName = "Freight";
siAverage.DisplayFormat = "Average: {0:#.#}";
gridView1.Columns["Freight"].Summary.Add(siAverage);
vb
Imports DevExpress.XtraGrid

gridView1.OptionsView.ShowFooter = True

Dim siTotal As New GridColumnSummaryItem()
siTotal.SummaryType = SummaryItemType.Count
siTotal.DisplayFormat = "{0} records"
colOrderID.Summary.Add(siTotal)

Dim siAverage As New GridColumnSummaryItem()
siAverage.SummaryType = SummaryItemType.Average
siAverage.FieldName = "Freight"
siAverage.DisplayFormat = "Average: {0:#.#}"
gridView1.Columns("Freight").Summary.Add(siAverage)

These five aggregate functions do not limit the types of summaries you can use. You can implement your own aggregate functions. For this purpose, set the SummaryType property to the SummaryItemType.Custom value and write a GridView.CustomSummaryCalculate event handler.

The following code snippets (auto-collected from DevExpress Examples) contain references to the SummaryType property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

xaf-how-to-extend-the-application-model/CS/EFCore/ExtendModelEF/ExtendModelEF.Win/Controllers/WinGroupFooterViewController.cs#L21

csharp
if (modelColumn != null) {
    modelColumn.GroupFooterSummaryType = gridView.GroupSummary[i].SummaryType;
}

winforms-grid-customize-footer-menu-calculate-custom-totals/CS/Form1.cs#L52

csharp
DevExpress.XtraGrid.Menu.GridViewFooterMenu footerMenu = e.Menu as DevExpress.XtraGrid.Menu.GridViewFooterMenu;
bool check = e.HitInfo.Column.SummaryItem.SummaryType == DevExpress.Data.SummaryItemType.Custom && Equals("Count", e.HitInfo.Column.SummaryItem.Tag);
DevExpress.Utils.Menu.DXMenuItem menuItem = new DevExpress.Utils.Menu.DXMenuCheckItem("Active Count", check, null, new EventHandler(MyMenuItem));

winforms-pivot-grid-create-the-underlying-data-source-asynchronously/CS/XtraPivotGrid_CreateDrillDownDataSourceAsync/DrillDownForm.cs#L32

csharp
{
    gridView1.Columns["OrderDate"].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count;
    gridView1.Columns["OrderDate"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;

winforms-grid-print-custom-draw-content/CS/MyXtraGrid/MyGridView/MyGridViewPrintInfo.cs#L34

csharp
{
    if (colInfo.Column.SummaryItem.SummaryType == SummaryItemType.None) continue;
    Rectangle r = Rectangle.Empty;

winforms-grid-customize-footer-menu-calculate-custom-totals/VB/Form1.vb#L45

vb
Dim footerMenu As DevExpress.XtraGrid.Menu.GridViewFooterMenu = TryCast(e.Menu, DevExpress.XtraGrid.Menu.GridViewFooterMenu)
Dim check As Boolean = e.HitInfo.Column.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom AndAlso Equals("Count", e.HitInfo.Column.SummaryItem.Tag)
Dim menuItem As DevExpress.Utils.Menu.DXMenuItem = New DevExpress.Utils.Menu.DXMenuCheckItem("Active Count", check, Nothing, New EventHandler(AddressOf MyMenuItem))

winforms-pivot-grid-create-the-underlying-data-source-asynchronously/VB/XtraPivotGrid_CreateDrillDownDataSourceAsync/DrillDownForm.vb#L26

vb
Friend Sub ArrangeLayout()
    gridView1.Columns("OrderDate").SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Count
    gridView1.Columns("OrderDate").DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime

winforms-grid-print-custom-draw-content/VB/MyXtraGrid/MyGridView/MyGridViewPrintInfo.vb#L32

vb
For Each colInfo As PrintColumnInfo In Columns
    If colInfo.Column.SummaryItem.SummaryType = SummaryItemType.None Then
        Continue For

See Also

SummaryItemType

Summaries

Working with Total, Group, and Custom Summaries in Code

GridSummaryItem Class

GridSummaryItem Members

DevExpress.XtraGrid Namespace