windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridview-cb99788e.md
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
[DXCategory("Data")]
public event CustomSummaryExistEventHandler CustomSummaryExists
<DXCategory("Data")>
Public Event CustomSummaryExists As CustomSummaryExistEventHandler
The CustomSummaryExists event's data class is CustomSummaryExistEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Exists | Gets or sets whether the summary value should be calculated and displayed. |
| GroupLevel | Gets the nesting level of the group whose summary value is being calculated. |
| GroupRowHandle | Gets a value identifying the group row whose summary value is about to be calculated. |
| IsGroupSummary | Gets whether a group summary value is about to be calculated. |
| IsTotalSummary | Gets whether a total summary value is about to be calculated. |
| Item | Gets a summary item whose value is about to be calculated. |
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.
//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;
}
}
'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
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.
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;
}
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