corelibraries-devexpress-dot-data-dot-virtualservermodesource-fdeb6e6f.md
Fires when a grid control asks the data source to calculate total summaries.
Namespace : DevExpress.Data
Assembly : DevExpress.Data.v25.2.dll
NuGet Package : DevExpress.Data
public event EventHandler<VirtualServerModeTotalSummaryEventArgs> TotalSummary
Public Event TotalSummary As EventHandler(Of VirtualServerModeTotalSummaryEventArgs)
The TotalSummary event's data class is VirtualServerModeTotalSummaryEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CancellationToken | Gets a token that allows you to respond to a task cancellation request invoked by the grid control. |
| ConfigurationInfo | Gets information on the grid’s current sorting, filtering and summary configuration. |
| NotReadyObject | This member supports the internal infrastructure. |
| TotalSummaryTask | Gets or sets the task that returns the requested summary value. |
The event data class exposes the following methods:
| Method | Description |
|---|---|
| NotifyIntermediateSummaryReady(IDictionary<ServerModeSummaryDescriptor, Object>) | |
| NotifySummaryReady(IDictionary<ServerModeSummaryDescriptor, Object>) | Allows you to update the bound grid control with intermediate summary values. |
To supply the requested total summary values, create a Task that calculates these values and assign it to the VirtualServerModeTotalSummaryEventArgs.TotalSummaryTask event parameter. Use the VirtualServerModeTotalSummaryEventArgs.ConfigurationInfo parameter to identify the requested summaries.
You can provide the bound grid with intermediate summary results during the task execution. To accomplish this, call the VirtualServerModeTotalSummaryEventArgs.NotifyIntermediateSummaryReady method from the Task.
The created Task must return final values for all requested summaries, including those whose intermediate values are supplied with the NotifyIntermediateSummaryReady method.
Tip
A Task typically executes asynchronously. To return summary values synchronously, create the task with the Task.FromResult method (available in .NET Framework 4.5+).
This example demonstrates how to handle the TotalSummary event to calculate the total summaries.
using using DevExpress.Data;
using using DevExpress.Data.Filtering;
using using System.Collections.Generic;
private void VirtualServerModeSource1_TotalSummary(object sender, VirtualServerModeTotalSummaryEventArgs e) {
e.TotalSummaryTask = new System.Threading.Tasks.Task<IDictionary<ServerModeSummaryDescriptor, object>>(GetSummaries, e.ConfigurationInfo.TotalSummary);
}
IDictionary<ServerModeSummaryDescriptor, object> GetSummaries(object descriptors) {
Dictionary<ServerModeSummaryDescriptor, object> results = new Dictionary<ServerModeSummaryDescriptor, object>();
int i = 0;
foreach (ServerModeSummaryDescriptor descriptor in descriptors as ServerModeSummaryDescriptor[]) {
results.Add(descriptor, GetSummary(descriptor.SummaryPropertyName, descriptor.SummaryType, i++));
}
return results;
}
object GetSummary(string fieldName, Aggregate summaryType, int index) {
if (fieldName == "ID" && summaryType == Aggregate.Sum && index == 0)
return 5;
if (fieldName == "ID" && summaryType == Aggregate.Avg && index == 1)
return 10;
if (fieldName == "ID" && summaryType == Aggregate.Avg && index == 2)
return 15;
return null;
}
Imports using DevExpress.Data
Imports using DevExpress.Data.Filtering
Imports using System.Collections.Generic
Private Sub VirtualServerModeSource1_TotalSummary(ByVal sender As Object, ByVal e As VirtualServerModeTotalSummaryEventArgs)
e.TotalSummaryTask = New System.Threading.Tasks.Task(Of IDictionary(Of ServerModeSummaryDescriptor, Object))(AddressOf GetSummaries, e.ConfigurationInfo.TotalSummary)
End Sub
Private Function GetSummaries(ByVal descriptors As Object) As IDictionary(Of ServerModeSummaryDescriptor, Object)
Dim results As New Dictionary(Of ServerModeSummaryDescriptor, Object)()
Dim i As Integer = 0
For Each descriptor As ServerModeSummaryDescriptor In TryCast(descriptors, ServerModeSummaryDescriptor())
results.Add(descriptor, GetSummary(descriptor.SummaryPropertyName, descriptor.SummaryType, i))
i += 1
Next descriptor
Return results
End Function
Private Function GetSummary(ByVal fieldName As String, ByVal summaryType As Aggregate, ByVal index As Integer) As Object
If fieldName = "ID" AndAlso summaryType Is Aggregate.Sum AndAlso index = 0 Then
Return 5
End If
If fieldName = "ID" AndAlso summaryType Is Aggregate.Avg AndAlso index = 1 Then
Return 10
End If
If fieldName = "ID" AndAlso summaryType Is Aggregate.Avg AndAlso index = 2 Then
Return 15
End If
Return Nothing
End Function
See Also