I have a Silverlight RadGridView (Telerik v2010.3.1314.1040) being populated by a call to a user-defined stored procedure (so the columns are not known until runtime). I'm attempting to add some aggregation functions to a couple of the columns and I am running into issues. CountFunction, MaxFunction and MinFunction work fine, but if I try to use AverageFunction or SumFunction I get the following exception:
No generic method 'Average' 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.
occurred at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateMethodCallExpression(LambdaExpression memberSelectorExpression)
at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilder.CreateAggregateExpression()
at Telerik.Windows.Data.EnumerableSelectorAggregateFunction.CreateAggregateExpression(Expression enumerableExpression)
at Telerik.Windows.Data.Expressions.GroupDescriptorExpressionBuilder.<ProjectionPropertyValueExpressions>b__3(AggregateFunction f)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
... (lots more)
The code I'm using looks something like this (the following has been simplified for readability/relevance):
RadGridView gridView = // get this from calling code...
GridViewDataColumn gridColumn = new GridViewDataColumn();
// ... lots of code to set up the column dynamically ...
AggregateFunction fn = new SumFunction(); // MaxFunction, MinFunction, CountFunction work fn.Caption = "Sum: "; gridColumn.AggregateFunctions.Add(fn); gridView.ShowColumnFooters = true;
The column in question contains an int value, but I'm getting the same issue with float, double and Decimal.
Any help would be appreciated.
Jeff Sumner
11 Answers, 1 is accepted
You should define your dynamic columns in an appropriate manner. You did not post all the code, but I assume that you haven't bind your column when you create it. This way you add an aggregate, but it does not know what to calculated because the DataMemberBinding is missing.
I would suggest you to change your code as follows:
GridViewDataColumn gridColumn =
new
GridViewDataColumn();
gridColumn.DataMemberBinding =
new
Binding(
"StadiumCapacity"
);
AggregateFunction fn =
new
MaxFunction();
fn.Caption =
"Sum: "
;
gridColumn.AggregateFunctions.Add(fn);
clubsGrid.Columns.Add(gridColumn);
clubsGrid.ShowColumnFooters =
true
;
where "StadiumCapacity" is the name of the property to be binded.
Could you please apply this change and if you still have the problem, could you please provide your entire code for the column with aggregate?
Didie
the Telerik team
Here's the full binding code for my column:
GridViewDataColumn gridColumn = new GridViewDataColumn();
gridColumn.Header = column.ColumnName;
gridColumn.DataType = column.DataType;
gridColumn.DataMemberBinding = new Binding(string.Format("RowData[{0}]", column.ColumnIndex));
gridColumn.DataMemberBinding.Mode = BindingMode.OneWay;
gridColumn.IsReadOnly = true;
gridColumn.UniqueName = column.ColumnName;
gridColumn.IsVisible = true;
AggregateFunction fn = new AverageFunction(); // MaxFunction/MinFunction work!
fn.Caption = "Avg: ";
gridColumn.AggregateFunctions.Add(fn);
Jeff
Sum and Average functions can not be applied if specified DataMemberBinding is not numeric. If you take a look at the provided snippet you have used String.Format and by that reason the exception occured.
You have to change the binding to a numeric and then everything should work as expected.
Vanya Pavlova
the Telerik team
You may submit a support ticket where you can attach your application from Your Account -> GetSupport, please follow this link.
Greetings,
Vanya Pavlova
the Telerik team
I have already replied in your support ticket.
Vanya Pavlova
the Telerik team
It seems that index column binding only support Max and Mix aggregation but not Average and Sum
Is this solved ? Can someone put the solution here
Hi All,
I'm having the exact same issue but couldn't find a solution anywhere,
I'm binding to a number field and data is showed correctly in the grid except for the sum where I always get 0.
Tried a custom aggregate and got:
Error details:
No generic method 'SumSumFunction' on type '....ProdBalance.Sum' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.
at System.Linq.Expressions.Expression.FindMethod(Type type, String methodName, Type[] typeArgs, Expression[] args, BindingFlags flags)
at System.Linq.Expressions.Expression.Call(Type type, String methodName, Type[] typeArguments, Expression[] arguments)
at Telerik.Windows.Data.Expressions.EnumerableSelectorAggregateFunctionExpressionBuilderBase.CreateMethodCallExpression(LambdaExpression
As previously mentioned in this thread, Sum function can only be applied to numeric values and the exception you're seeing will occur if you're trying to sum non-numeric types.
Could you please verify that you are summing numeric values in the custom aggregate? If you take a look at this article, for example, the AggregateFunction adds together the values of the numeric Number property the respective object.
In case this is not the cause for the issue, we'd appreciate it if you can open a new support ticket and send us a small demo project showing your setup.
Regards,
Petya
Telerik