Class GridQueryCustomSummaryEventArgs
Holds a reference to a GridSummaryColumnDescriptor and SummaryDescriptor and lets you fill in the CreateSummaryMethod or CreateSummaryFromElementMethod with a CreateSummaryFromElementDelegate that can instantiate custom ITreeTableSummary objects.
Inheritance
Inherited Members
Namespace: Syncfusion.Windows.Forms.Grid.Grouping
Assembly: Syncfusion.Grid.Grouping.Windows.dll
Syntax
public sealed class GridQueryCustomSummaryEventArgs : SyncfusionHandledEventArgs
Remarks
See the Grid\Grouping\CustomSummaries example how to implement custom summaries:
Examples
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// Setup custom summaries
this.gridGroupingControl1.QueryCustomSummary += new GridQueryCustomSummaryEventHandler(gridGroupingControl1_QueryCustomSummary);
GridSummaryColumnDescriptor sd1 = new GridSummaryColumnDescriptor();
sd1.Name = "QuantityTotal";
sd1.DataMember = "Quantity";
sd1.DisplayColumn = "Quantity";
sd1.Format = "{Total}";
sd1.SummaryType = SummaryType.Custom;
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 1", "Total", sd1));
}
private void gridGroupingControl1_QueryCustomSummary(object sender, GridQueryCustomSummaryEventArgs e)
{
switch (e.SummaryColumn.Name)
{
case "QuantityTotal":
{
e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(TotalSummary.CreateSummaryMethod);
break;
}
}
}
public sealed class TotalSummary : SummaryBase
{
double _total;
public static readonly TotalSummary Empty = new TotalSummary(0);
public static ISummary CreateSummaryMethod(SummaryDescriptor sd, Record record)
{
object obj = sd.GetValue(record);
bool isNull = (obj == null || obj is DBNull);
if (isNull)
return Empty;
else
{
double val = Convert.ToDouble(obj);
return new TotalSummary(val);
}
}
public TotalSummary(double total)
{
_total = total;
}
public double Total
{
get
{
return _total;
}
}
public override SummaryBase Combine(SummaryBase other)
{
return Combine((TotalSummary) other);
}
/// a new summary object instead of modifying an existing summary object.
public TotalSummary Combine(TotalSummary other)
{
// Summary objects are immutable. That means properties cannot be modified for an
// existing object. Instead every time a change is made a new object must be created (just like
// System.String).
//
// This allows following optimization: return existing summary object if either one of the values is 0. --
if (other.Total == 0)
return this;
else if (Total == 0)
return other;
// -- end of optimization
else
return new TotalSummary(this.Total + other.Total);
}
public override string ToString()
{
return String.Format("Total = {0:0.00}", Total);
}
}
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
'
' Required for Windows Form Designer support
'
InitializeComponent()
' Setup custom summaries
AddHandler Me.gridGroupingControl1.QueryCustomSummary, AddressOf gridGroupingControl1_QueryCustomSummary
Dim sd1 As New GridSummaryColumnDescriptor()
sd1.Name = "QuantityTotal"
sd1.DataMember = "Quantity"
sd1.DisplayColumn = "Quantity"
sd1.Format = "{Total}"
sd1.SummaryType = SummaryType.Custom
Me.gridGroupingControl1.TableDescriptor.SummaryRows.Add(New GridSummaryRowDescriptor("Row 1", "Total", sd1))
End Sub 'New
Private Sub gridGroupingControl1_QueryCustomSummary(ByVal sender As Object, ByVal e As GridQueryCustomSummaryEventArgs)
Select Case e.SummaryColumn.Name
Case "QuantityTotal"
e.SummaryDescriptor.CreateSummaryMethod = New CreateSummaryDelegate(AddressOf TotalSummary.CreateSummaryMethod)
Exit Select
Case "QuantityDistinctCount"
e.SummaryDescriptor.CreateSummaryMethod = New CreateSummaryDelegate(AddressOf DistinctInt32CountSummary.CreateSummaryMethod)
Exit Select
Case "QuantityMedian"
e.SummaryDescriptor.CreateSummaryMethod = New CreateSummaryDelegate(AddressOf StatisticsSummary.CreateSummaryMethod)
Exit Select
End Select
End Sub 'gridGroupingControl1_QueryCustomSummary
NotInheritable Public Class TotalSummary
Inherits SummaryBase
Private _total As Double
Public Shared Empty As New TotalSummary(0)
Public Shared Function CreateSummaryMethod(ByVal sd As SummaryDescriptor, ByVal record As Record) As ITreeTableSummary
Dim obj As Object = sd.GetValue(record)
Dim isNull As Boolean = obj Is Nothing OrElse TypeOf obj Is DBNull
If isNull Then
Return Empty
Else
Dim val As Double = Convert.ToDouble(obj)
Return New TotalSummary(val)
End If
End Function 'CreateSummaryMethod
Public Sub New(ByVal total As Double)
_total = total
End Sub 'New
Public ReadOnly Property Total() As Double
Get
Return _total
End Get
End Property
Public Overloads Overrides Function Combine(ByVal other As SummaryBase) As SummaryBase
Return Combine(CType(other, TotalSummary))
End Function 'Combine
Public Overloads Function Combine(ByVal other As TotalSummary) As TotalSummary
' Summary objects are immutable. That means properties cannot be modified for an
' existing object. Instead every time a change is made a new object must be created (just like
' System.String).
'
' This allows following optimization: return existing summary object if either one of the values is 0. --
If other.Total = 0 Then
Return Me
ElseIf Total = 0 Then
Return other
' -- end of optimization
Else
Return New TotalSummary(Me.Total + other.Total)
End If
End Function 'Combine
Public Overrides Function ToString() As String
Return String.Format("Total = {0:0.00}", Total)
End Function 'ToString
End Class 'TotalSummary
Constructors
GridQueryCustomSummaryEventArgs(GridSummaryColumnDescriptor, SummaryDescriptor)
Initializes a new instance of the GridQueryCustomSummaryEventArgs class with the specified instance of the GridSummaryColumnDescriptor and SummaryDescriptor classes.
Declaration
public GridQueryCustomSummaryEventArgs(GridSummaryColumnDescriptor summaryColumn, SummaryDescriptor sd)
Parameters
Type | Name | Description |
---|---|---|
GridSummaryColumnDescriptor | summaryColumn | The summary column descriptor. |
SummaryDescriptor | sd | The summary descriptor. |
Properties
SummaryColumn
Gets the summary column descriptor of the current object.
Declaration
[TraceProperty(true)]
public GridSummaryColumnDescriptor SummaryColumn { get; }
Property Value
Type |
---|
GridSummaryColumnDescriptor |
SummaryDescriptor
Gets the summary descriptor of the current object.
Declaration
[TraceProperty(true)]
public SummaryDescriptor SummaryDescriptor { get; }
Property Value
Type |
---|
SummaryDescriptor |