Completed
Last Updated: 16 Aug 2023 10:51 by ADMIN
Release R3 2023 (LIB 2023.2.816)
Tony
Created on: 12 Jun 2023 12:30
Category: GridView
Type: Bug Report
1
RadGridView: GridAggregateFunction.StDev causes DivideByZeroException if all values are equal to 0 in the column

Code snippet for reproducing the error: 

            DataTable dt = new DataTable();
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Title", typeof(string));
            dt.Columns.Add("Price", typeof(decimal));

            for (int i = 0; i < 10; i++)
            {
                dt.Rows.Add(i, "Row" + i, 0);
            }

            this.radGridView1.DataSource = dt;
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            GridViewSummaryItem summaryItem = new GridViewSummaryItem();
            summaryItem.Name = "Price";
            summaryItem.Aggregate = GridAggregateFunction.StDev;
            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
            summaryRowItem.Add(summaryItem); 
            this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 12 Jun 2023 12:41

Hi, Tony,

Thank you for bringing this to our attention. We will do our best to introduce a proper fix. Meanwhile, the possible solution that I can suggest is to use the following custom summary item: 

        public RadForm1()
        {
            InitializeComponent();

            DataTable dt = new DataTable();
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Title", typeof(string));
            dt.Columns.Add("Price", typeof(decimal));

            for (int i = 0; i < 10; i++)
            {
                dt.Rows.Add(i, "Row" + i, 0);
            }

            this.radGridView1.DataSource = dt;
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            CustomSummaryItem summaryItem = new CustomSummaryItem("Price", "{0}",GridAggregateFunction.StDev);
           
            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
            summaryRowItem.Add(summaryItem); 
            this.radGridView1.SummaryRowsBottom.Add(summaryRowItem);
        }

        public class CustomSummaryItem : GridViewSummaryItem
        {
            public CustomSummaryItem(string name, string formatString, GridAggregateFunction aggregate) : base(name, formatString, aggregate)
            {
            }

            [Description("Returns the standard deviation from the specified expression")]
            public override object Evaluate(IHierarchicalRow row)
            {
                decimal value = 0;
                try
                {
                    value = (decimal)base.Evaluate(row);
                }
                catch (Exception)
                {
                    return 0;
                }
                return value;
            }
        }

Please excuse us for the inconvenience caused.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.