Back to Devexpress

GridView.CustomSummaryExists Event

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-cb99788e.md

latest7.5 KB
Original Source

GridView.CustomSummaryExists Event

Enables you to specify which summaries should be calculated and displayed.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

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

Declaration

csharp
[DXCategory("Data")]
public event CustomSummaryExistEventHandler CustomSummaryExists
vb
<DXCategory("Data")>
Public Event CustomSummaryExists As CustomSummaryExistEventHandler

Event Data

The CustomSummaryExists event's data class is CustomSummaryExistEventArgs. The following properties provide information specific to this event:

PropertyDescription
ExistsGets or sets whether the summary value should be calculated and displayed.
GroupLevelGets the nesting level of the group whose summary value is being calculated.
GroupRowHandleGets a value identifying the group row whose summary value is about to be calculated.
IsGroupSummaryGets whether a group summary value is about to be calculated.
IsTotalSummaryGets whether a total summary value is about to be calculated.
ItemGets a summary item whose value is about to be calculated.

Remarks

The event is raised before a particular summary value is calculated. There are two cases depending on the summary type:

The example below illustrates how to skip calculating summaries for a specific column.

csharp
//Add a group "Count" summary
GridSummaryItem item1 = gridView1.GroupSummary.Add();
item1.SummaryType = DevExpress.Data.SummaryItemType.Count;
item1.Tag = 1;

//Add a group summary for the "Extended Price" column
GridSummaryItem item2 = gridView1.GroupSummary.Add();
item2.FieldName = "ExtendedPrice";
item2.SummaryType = DevExpress.Data.SummaryItemType.Sum;
item2.Tag = 2;
item2.DisplayFormat = "Sum={0:c2}";

// Do not calculate the Sum function (Tag=2) for City group rows  
private void gridView1_CustomSummaryExists(object sender, DevExpress.Data.CustomSummaryExistEventArgs e) {
    GridView view = sender as GridView;
    int summaryTag = Convert.ToInt32((e.Item as GridSummaryItem).Tag);
    GridColumn groupColumn = view.GroupedColumns[e.GroupLevel];
    if (groupColumn.FieldName == "City" && summaryTag == 2) {
        e.Exists = false;
    }
}
vb
'Add a group "Count" summary
Private item1 As GridSummaryItem = gridView1.GroupSummary.Add()
item1.SummaryType = DevExpress.Data.SummaryItemType.Count
item1.Tag = 1

'Add a group summary for the "Extended Price" column
Dim item2 As GridSummaryItem = gridView1.GroupSummary.Add()
item2.FieldName = "ExtendedPrice"
item2.SummaryType = DevExpress.Data.SummaryItemType.Sum
item2.Tag = 2
item2.DisplayFormat = "Sum={0:c2}"

' Do not calculate the Sum function (Tag=2) for City group rows  
private void gridView1_CustomSummaryExists(Object sender, DevExpress.Data.CustomSummaryExistEventArgs e)
    Dim view As GridView = TryCast(sender, GridView)
    Dim summaryTag As Integer = Convert.ToInt32((TryCast(e.Item, GridSummaryItem)).Tag)
    Dim groupColumn As GridColumn = view.GroupedColumns(e.GroupLevel)
    If groupColumn.FieldName = "City" AndAlso summaryTag = 2 Then
        e.Exists = False
    End If

Example

By default, the Data Grid calculates group summaries (GridView.GroupSummary) for each group level. The following example handles the GridView.CustomSummaryExists event to allow a Count group summary to be only calculated for the root level and prevent it from being calculated for nested data groups.

The image below demonstrates the result.

csharp
using DevExpress.XtraGrid;

private void gridView1_CustomSummaryExists(object sender, DevExpress.Data.CustomSummaryExistEventArgs e) {
    GridGroupSummaryItem item = e.Item as GridGroupSummaryItem;
    if (item == null) return;
    if (e.GroupLevel > 0 && item.SummaryType == DevExpress.Data.SummaryItemType.Count)
        e.Exists = false;
}
vb
Imports DevExpress.XtraGrid

Private Sub GridView1_CustomSummaryExists(sender As Object, e As CustomSummaryExistEventArgs) Handles GridView1.CustomSummaryExists
    Dim item As GridGroupSummaryItem = TryCast(e.Item, GridGroupSummaryItem)
    If (item Is Nothing) Then Return
    If (e.GroupLevel > 0 AndAlso item.SummaryType = DevExpress.Data.SummaryItemType.Count) Then
        e.Exists = False
    End If
End Sub

See Also

Summaries

Working with Total, Group, and Custom Summaries in Code

GridView Class

GridView Members

DevExpress.XtraGrid.Views.Grid Namespace