)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create weighted summaries in the WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: April 30, 2011 |
Last Revised Date: February 12, 2020
Tags: summary

Custom summary

You can create a custom summary that does weighted average calculations by using a code-naming convention to pass the column holding the weights to the summary descriptor.

C#

void TableDescriptor_QueryCustomSummary(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridQueryCustomSummaryEventArgs e)
{
    //Check whether the summary type is custom or not.
    if (e.SummaryDescriptor.SummaryType == SummaryType.Custom)
    {
        //Method to calculate weighted summaries.
        e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(Weightedsummaries.CreateSummaryMethod);
    }
    e.Handled = true;
}
private GridSummaryColumnDescriptor GetWeightedSummaryColumnDescriptor(string sourceCol, string weightCol)
{
    GridSummaryColumnDescriptor wgtSumCol = new GridSummaryColumnDescriptor();
    wgtSumCol.Name = string.Format("{0}_{1}", sourceCol, weightCol); //Special name following the convention above.
    wgtSumCol.DataMember = sourceCol; //The column this summary is applied to.
    wgtSumCol.DisplayColumn = sourceCol; //Where this summary is displayed.
    wgtSumCol.Format = "{WeightedAverage:#.##}"; //What is displayed in the summary.
    wgtSumCol.SummaryType = SummaryType.Custom; //Marks this as a CustomSummary.
    wgtSumCol.Appearance.AnySummaryCell.HorizontalAlignment = GridHorizontalAlignment.Right;
    wgtSumCol.MaxLength = 6;
    return wgtSumCol;
}

VB

Private Sub TableDescriptor_QueryCustomSummary(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridQueryCustomSummaryEventArgs)
    'Check whether the summary type is custom or not.
    If e.SummaryDescriptor.SummaryType = SummaryType.Custom Then
        'Method to calculate weighted summaries.
        e.SummaryDescriptor.CreateSummaryMethod = New CreateSummaryDelegate(Weightedsummaries.CreateSummaryMethod)
    End If
    e.Handled = True
End Sub
Private Function GetWeightedSummaryColumnDescriptor(ByVal sourceCol As String, ByVal weightCol As String) As GridSummaryColumnDescriptor
    Dim wgtSumCol As New GridSummaryColumnDescriptor()
    wgtSumCol.Name = String.Format("{0}_{1}", sourceCol, weightCol) 'Special name following the convention above.
    wgtSumCol.DataMember = sourceCol 'The column this summary is applied to.
    wgtSumCol.DisplayColumn = sourceCol 'Where this summary is displayed.
    wgtSumCol.Format = "{WeightedAverage:#.##}" 'What is displayed in the summary.
    wgtSumCol.SummaryType = SummaryType.Custom 'Marks this as a CustomSummary.
    wgtSumCol.Appearance.AnySummaryCell.HorizontalAlignment = GridHorizontalAlignment.Right
    wgtSumCol.MaxLength = 6
    Return wgtSumCol
End Function

Samples:

C#: Weighted_summaries

VB: Weighted_summaries

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/summaries#custom-summaries

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon