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

AggregateFunctions code behind crashes on SumFunction

9 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Harrigan
Top achievements
Rank 1
Richard Harrigan asked on 19 Jan 2014, 08:20 PM

Hi



I am creating AggregateFunctions code-behind (see example code below).  The CountFunction works but when I include a SumFunction the program crashes with the following error:



No generic method 'Sum' on type

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



I can only see two possible explanations:

1. I am not setting the AggregateFunction properties correctly.

2. Setting Grid.ItemsSource to ObservableCollection<dynamic>

This collections data is correct since is working correctly when not using AggregateFunctions.

Is a dynamically created class a problem?  The actual class properties are not dynamic but the actual system data types.



I am also using Grouping and it also works correctly.  To make sure that grouping was not the problem I eliminated the grouping but the program still crashes.


---- The following is being looped ----

GridViewDataColumn dataCol = new GridViewDataColumn();

dataCol.DataMemberBinding = new Binding(column.ColumnName);

dataCol.Header = column.ColumnName;

dataCol.UniqueName = column.ColumnName;

dataCol.DataType = Type.GetType(column.SystemDataType);

dataCol.FilterMemberType = Type.GetType(column.SystemDataType);

--- Hard coded to test AggregateFunctions

if (dataCol.UniqueName == "Uid")

{

 SumFunction sumFunction = new SumFunction();

 sumFunction.SourceField = "Uid";

        sumFunction.ResultFormatString = "Tot Uid: {0}";

        sumFunction.SourceFieldType = Type.GetType(column.SystemDataType);     // System.Int32

        dataCol.AggregateFunctions.Add(sumFunction);


}

--- End hard coding ---

grid.Columns.Add(dataCol);

---- End of Loop ----


grid.ShowColumnFooters = true;

grid.ShowGroupFooters = true;

grid.ItemsSource = new QueryableCollectionView(clientData.Result);

Crashed at this point setting the ItemsSource.

Before putting in the SumFunction code everything was working correctly!

clientData.Result is ObservableCollection<dynamic>



====================================

If you don't have the answer could you provide the code-behind to create AggregrateFunctions.  The following xaml snippet is from the WPF example Aggregates which is under the Grouping and Aggregates category.  In looking at numerous past posts of this problem I think it would be most helpful to many developers to take the aggregate example and define the grid properties in code-behind.  I would like to see a AggregateFunctions example that works using code-behind.



Thanks

Rich





<telerik:GridViewDataColumn Header="Freight"

           DataMemberBinding="{Binding Freight, StringFormat=c}">

                    <telerik:GridViewDataColumn.AggregateFunctions>

                        <telerik:SumFunction SourceField="Freight" ResultFormatString="Total: {0:c}" />

                    </telerik:GridViewDataColumn.AggregateFunctions>

 </telerik:GridViewDataColumn>






9 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 20 Jan 2014, 11:34 AM
Hello Richard,

Thank you for contacting us.

I would suggest you to check this troubleshooting article for a reference.

I hope this helps.


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Richard Harrigan
Top achievements
Rank 1
answered on 20 Jan 2014, 03:57 PM

Hi Yoan


That article did not help.



Can you please provide a simple working example of SumFunction in code-behind. I would suggest using RadGridView/Grouping and Aggregates/ Aggregate example form the WPF examples and replace the AggregateFunctions xaml code with code-behind.  I've seen many references to that article and I am beginning to wonder if SumFunction actually works in code-behind.  I think its time for a working SumFunction code-behind example.



Please reread my previous post.  Am I doing anything wrong? 



Thanks

Rich

0
Yoan
Telerik team
answered on 23 Jan 2014, 03:39 PM
Hello Rich,

Please find attached a sample project that show you how to add the aggregate function
in code behind. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Richard Harrigan
Top achievements
Rank 1
answered on 24 Jan 2014, 06:56 PM

Hi Yoan,


Thanks for making the effort to get me example code.  Unfortunately, it does not work in my case (See attached VS debug image that shows a sample of what my itemssource data looks like.   It must be because the data was created dynamically.  I guess this means that I am going to need Custom AggregateFunctions for Sum, Avg etc.  If you would be so kind could you modify your sample code to use a custom SumFunction instead of the built in SumFunction.  I would think that this function would take as input a reference to the column item collection and the columns datatype.  The custom function would execute the appropriate code for the datatype.



The reason I need this capability is that I have written a program that generates Ad-Hoc queries for non technical users.  I would like to provide them AggregateFunction capabilities on the query result via my UI interface.  I have been told by my users that this is important for them.



Thanks

Rich



0
Yoan
Telerik team
answered on 29 Jan 2014, 06:01 PM
Hi Rich,

I can also suggest you to check this online demo, which demonstrates how to create custom aggregate function. Would you try to implement it in your project? Please if you face any difficulties do not hesitate to ask.


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Richard Harrigan
Top achievements
Rank 1
answered on 29 Jan 2014, 06:26 PM
Hi,

I already tried that demo.  I could not get it to compile since I don't have access to all the  parts.  I want to have a running program to test.  Could you send me a version of that example that I can compile.

Thanks
Rich
0
Yoan
Telerik team
answered on 03 Feb 2014, 04:40 PM
Hi Rich,

Please find attached a sample project based on the mentioned demo. However, may I ask you to verify that your Sum function has valid Type:
sumFunction.ResultFormatString = "Tot Uid: {0}";
sumFunction.SourceFieldType = Type.GetType(column.SystemDataType);

Looking forward to hearing from you!


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Richard Harrigan
Top achievements
Rank 1
answered on 05 Feb 2014, 06:26 PM
Hi,

That was a good example and it helped me understand AggregateFunction better.  However, instead of declaring the custom aggregate function in xaml could you create it in code-behind and show how it gets executed.  Also if there is a way to pass an additional parameter to the aggregate function?  If so could you also show that.

Thanks for your help
Rich
0
Richard Harrigan
Top achievements
Rank 1
answered on 06 Feb 2014, 12:09 AM
Hi,

Please ignore this request. I figured it out.

Thanks
Rich 
Tags
GridView
Asked by
Richard Harrigan
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Richard Harrigan
Top achievements
Rank 1
Share this question
or