How to sum the column in and display as hours godz., minutes min.

I have a column of MINUTES with int values and I would like to make a summary as a human readable text.

Zrzut ekranu 2025-02-24 123052.png

My code:

using Syncfusion.Data;
using Syncfusion.WinForms.DataGrid;
using Syncfusion.WinForms.DataGrid.Enums;
using Syncfusion.WinForms.DataGrid.Interactivity;
using System;
using System.Collections.Generic;
using System.Windows.Forms;


namespace eBHP_Program.mZarzadzanie
{
    public class CustomSummary : SummaryBase
    {
        private int totalMinutes;


        public override void Reset()
        {
            totalMinutes = 0;
        }


        public override void Combine(object result)
        {
            if (result is int)
            {
                totalMinutes += (int)result;
            }
        }


        public override void CombineSummary(SummaryBase summary)
        {
            if (summary is CustomSummary)
            {
                totalMinutes += ((CustomSummary)summary).totalMinutes;
            }
        }


        public override object GetResult()
        {
            int hours = totalMinutes / 60;
            int minutes = totalMinutes % 60;
            return $"{hours} godz {minutes} minut";
        }


        public override SummaryBase GetInstance()
        {
            return new CustomSummary();
        }


        public override object Aggregate(SummaryColumn summaryColumn, SummaryRecord summaryRecord)
        {
            if (summaryColumn.MappingName == "MINUT")
            {
                totalMinutes = 0;
                foreach (var record in summaryRecord.Records)
                {
                    totalMinutes += Convert.ToInt32(record.GetType().GetProperty(summaryColumn.MappingName).GetValue(record, null));
                }


                int hours = totalMinutes / 60;
                int minutes = totalMinutes % 60;


                return $"{hours} godz {minutes} minut";
            }
            return base.Aggregate(summaryColumn, summaryRecord);
        }
    }
}





Unfortunately, I keep getting an error - unknown type SummaryColumn and  SummaryRecord.

What i am doing wrong?


1 Reply

SG Santhosh Govindasamy Syncfusion Team February 25, 2025 10:34 AM UTC

Hi Wojciech Miszkiewicz,

Thank you for reaching out.


Based on the information and code snippet you provided, your requirement is to display the total summary value in DateTime format.


The SfDataGrid allows you to implement your own aggregate functions when the built-in aggregate functions do not meet your needs. Summary values can be calculated based on custom logic using the GridSummaryColumn.CustomAggregate property.


To achieve your requirement, please refer to the attached knowledge base article.

Link-> KB-Article


For your reference, we have also attached a link to the user guide on handling "Summaries." Please take a look at it.

Summaries | DataGrid Control for Windows Forms | Syncfusion®

Regards,
Santhosh.G


Loader.
Up arrow icon