Completed
Last Updated: 05 Sep 2014 08:18 by ADMIN
ADMIN
Stefan
Created on: 18 Aug 2014 09:07
Category: GridView
Type: Bug Report
0
FIX. RadGridView - throws exception when adding summary for TimeSpan column
To reproduce:

           DataTable t = new DataTable();
            t.Columns.Add("timeSpan", typeof(TimeSpan));
            t.Rows.Add(TimeSpan.FromHours(11));
            t.Rows.Add(TimeSpan.FromHours(2));
            t.Rows.Add(TimeSpan.FromHours(4));
            t.Rows.Add(TimeSpan.FromMinutes(17));

            radGridView1.DataSource = t;

            GridViewSummaryItem summaryItem = new GridViewSummaryItem();
            summaryItem.Name = "timeSpan";
            summaryItem.Aggregate = GridAggregateFunction.Sum;

            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
            summaryRowItem.Add(summaryItem);
            this.radGridView1.SummaryRowsTop.Add(summaryRowItem);

Workaround:
           CustomSummaryItem summaryItem = new CustomSummaryItem("timeSpan", "", GridAggregateFunction.Sum);
            GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
            summaryRowItem.Add(summaryItem);
            this.radGridView1.SummaryRowsTop.Add(summaryRowItem);

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

            public override object Evaluate(IHierarchicalRow row)
            {
                TimeSpan timeSpanSum = new TimeSpan();
                foreach (GridViewRowInfo childRow in row.ChildRows)
                {
                    timeSpanSum += (TimeSpan)childRow.Cells["timeSpan"].Value;
                }
                return timeSpanSum;
            }
        }
0 comments