How to use AggregateFunctions with SumFunction for a GridViewColumn?

2 posts, 0 answers
  1. Max
    Max avatar
    27 posts
    Member since:
    May 2013

    Posted 08 May 2013 Link to this post

    Hi,

    There is GridView with some columns and want to display total of one of the column which is having data of type System.Double. I had look at the same and tried to implement the same but it didn't work and end-up with following exception.

    Code
    <telerik:GridViewDataColumn DataMemberBinding="{Binding TravelRate, StringFormat=c}"
                                                UniqueName="TravelRate"
                                                Header="Travel Rate"
                                                MinWidth="100">
                        <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:SumFunction Caption="Sum: "
                                                 ResultFormatString="{}{0:c}"
                                                 SourceField="UnitPrice" />
                        </telerik:GridViewDataColumn.AggregateFunctions>
    </telerik:GridViewDataColumn>

    Exception
    No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

    I also had a look at another post where it's mentioned create custom aggregation function. I tried it but didn't get any success.

    Code
    public class SumFunction : EnumerableSelectorAggregateFunction
        {
            protected override string AggregateMethodName
            {
                get { return "Sum"; }
            }

            protected override Type ExtensionMethodsType
            {
                get
                {
                    return typeof(Amounts);
                }
            }
        }

        public static class Amounts
        {
            public static Double Sum<T>(IEnumerable<T> source, Func<T, Double> selector)
            {
                return source.Select(selector).Aggregate(Double.Parse("0"), (t1, t2) => t1 + t2);
            }
        }

    Can please some one help me with this?

    Thanks.

  2. Yoan
    Admin
    Yoan avatar
    1180 posts

    Posted 09 May 2013 Link to this post

    Hello Max,

    Thank you for writing to us.

    Unfortunately, we did not manage to reproduce the issue. We ran the code snippet you've sent us under dll version 2013.1.403.40  and it worked as expected. 

    Which dll versions you are using in your project?

    It would be of great help if you can send us a working sample where the issue can be observed in order to investigate it.

    Greetings,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top