This is a migrated thread and some comments may be shown as answers.

How to use AggregateFunctions with SumFunction for a GridViewColumn?

1 Answer 367 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 08 May 2013, 04:25 PM
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.

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 09 May 2013, 06:13 AM
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.

Tags
GridView
Asked by
Max
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or