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

Footer Sum - No method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied arguments.

9 Answers 364 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nic Roche
Top achievements
Rank 1
Nic Roche asked on 05 Nov 2009, 12:34 AM
Hi,

I've embedded a fairly simple example of an issue we have in the greater solution.

The Context:
Using a datatable as the source.
Adding a summary row for Hours (Int32)
Get the error:No method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied arguments.

<Window x:Class="Window1"    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"    
    xmlns:telerikdata="clr-namespace:Telerik.Windows.Data;assembly=Telerik.Windows.Data" 
    Title="Window1" WindowState="Maximized">  
    <Grid> 
        <telerik:RadGridView      
                        AutoGenerateColumns="False"    
                        HorizontalAlignment="Right"      
                        IsFilteringAllowed="False"    
                        CanUserFreezeColumns="False"      
                        CanUserReorderColumns="False"      
                        IsEnabled="True"    
                        ColumnsWidthMode="Auto"    
                        ShowColumnFooters="True" 
                        CanUserSortColumns="False"                     
                        ShowGroupPanel="False"    
                        ItemsSource="{Binding Tables[Labour.EmployeeLeave]}"    
                        > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewComboBoxColumn      
                                Header="Employee"      
                                DataMemberBinding="{Binding [EmpNum], Mode=TwoWay}"    
                                SelectedValueMemberPath="EmpNum"    
                                DisplayMemberPath="Fullname"    
                                ItemsSource="{Binding}"      
                                DataContext="{Binding Tables[Labour.Employee]}"/>  
                <telerik:GridViewDataColumn Header="Leave Type" UniqueName="LeaveCode" /> 
                <telerik:GridViewDataColumn Header="Date From" UniqueName="DateFrom" /> 
                <telerik:GridViewDataColumn Header="Date To" UniqueName="DateTo" /> 
                <telerik:GridViewDataColumn   
                    Header="Hours"   
                    DataMemberBinding="{Binding [Hours], Mode=TwoWay}" > 
                    <telerik:GridViewDataColumn.AggregateFunctions> 
                        <telerikdata:SumFunction Caption="Total: " SourceField="Hours" /> 
                    </telerik:GridViewDataColumn.AggregateFunctions> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn Header="Pay In Advance" UniqueName="PayInAdvance"/>  
                <telerik:GridViewDataColumn Header="Comments" UniqueName="Comments" /> 
                <telerik:GridViewDataColumn Header="Total Made" UniqueName="TotalMade" /> 
            </telerik:RadGridView.Columns> 
        </telerik:RadGridView> 
    </Grid> 
</Window>    
 

Imports System.Data  
 
Class Window1  
 
    Public Sub New()  
        InitializeComponent()  
        Dim ds As New DataSet  
        Dim dt As New DataTable("Labour.Employee")  
        Me.BuildEmployeesTable(dt)  
        ds.Tables.Add(dt)  
        dt = New DataTable("Labour.EmployeeLeave")  
        Me.BuildEmployeeLeaveTable(dt)  
        ds.Tables.Add(dt)  
        Me.DataContext = ds  
    End Sub 
 
    Private Sub BuildEmployeesTable(ByVal dt As DataTable)  
        dt.Columns.Add("EmpNum"GetType(System.Int32))  
        dt.Columns.Add("Firstname"GetType(System.String))  
        dt.Columns.Add("Surname"GetType(System.String))  
        dt.Columns.Add("Fullname"GetType(System.String), "Firstname+' '+Surname")  
        Me.AdddEmployeesRow(dt, 1, "Joe""Blogs")  
        Me.AdddEmployeesRow(dt, 2, "John""Doe")  
        Me.AdddEmployeesRow(dt, 3, "Mary""May")  
    End Sub 
 
    Private Sub BuildEmployeeLeaveTable(ByVal dt As DataTable)  
        dt.Columns.Add("EmpNum"GetType(System.Int32))  
        dt.Columns.Add("LeaveCode"GetType(System.String))  
        dt.Columns.Add("DateFrom"GetType(System.DateTime))  
        dt.Columns.Add("DateTo"GetType(System.DateTime))  
        dt.Columns.Add("Hours"GetType(System.Int32))  
        dt.Columns.Add("PayInAdvance"GetType(System.Boolean))  
        dt.Columns.Add("Comments"GetType(System.String))  
        dt.Columns.Add("TotalMade"GetType(String), "Comments+Hours")  
        Me.AdddEmployeeLeaveRow(dt, 1, "sss", Now, Now, 55, True"comment")  
        Me.AdddEmployeeLeaveRow(dt, 2, "sss", Now, Now, 22, True"comment")  
        Me.AdddEmployeeLeaveRow(dt, 3, "sss", Now, Now, 33, True"comment")  
    End Sub 
 
    Private Sub AdddEmployeesRow(ByVal dt As DataTable, ByVal id As IntegerByVal fname As StringByVal lname As String)  
        Dim dr As DataRow = dt.NewRow()  
        dr("EmpNum") = id  
        dr("Firstname") = fname  
        dr("Surname") = lname  
        dt.Rows.Add(dr)  
    End Sub 
 
    Private Sub AdddEmployeeLeaveRow(ByVal dt As DataTable, ByVal id As IntegerByVal LeaveCode As StringByVal DateFrom As DateTime, ByVal DateTo As DateTime, ByVal Hours As IntegerByVal PayInAdvance As BooleanByVal Comments As String)  
        Dim dr As DataRow = dt.NewRow()  
        dr("EmpNum") = id  
        dr("LeaveCode") = LeaveCode  
        dr("DateFrom") = DateFrom  
        dr("DateTo") = DateTo  
        dr("Hours") = Hours  
        dr("PayInAdvance") = PayInAdvance  
        dr("Comments") = Comments  
        dt.Rows.Add(dr)  
    End Sub 
 
End Class 
 

The last issue I had with datasets had a fairly simple fix. Hope this is the same.

Regards,
Nic Roche

9 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 10 Nov 2009, 12:23 PM
Hello Nic Roche,

Thanks for reporting this problem. After looking at the issue it seems that when ItemsSource is a data table we cannot correctly access the specified column and an exception is thrown.

The good news is that I was able to implement this functionality by adding a new property on the aggregate function - SourceFieldType. Please find updated version of your project that uses an internal build of RadControls for WPF. This "fix" will also be available in the latest internal build.

Thanks for pointing this out. I have updated your Telerik points.

All the best,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nic Roche
Top achievements
Rank 1
answered on 10 Nov 2009, 10:41 PM
Hi,

Thanks for your effort.

It does total on load but not with subsequent edits to the total column.

Can you point me in the right direction here?

Regards,
Nic Roche
0
Stefan Dobrev
Telerik team
answered on 12 Nov 2009, 03:50 PM
Hi Nic,

Currently we did not update the aggregates when something is changed. We will address this problem in our next service pack release. Till then you can use this simple one line workaround:
this.gridView.RowEditEnded += (s, args) => this.gridView.CalculateAggregates();

Hope this helps.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nic Roche
Top achievements
Rank 1
answered on 03 Dec 2009, 11:18 PM
Hi,

I finally was put back on this task and the call to CalculateAggregates did not update the footer totals.

The only difference is that our implementation was in VB and this call was made:
    Private Sub gridView_RowEditEnded(ByVal sender As System.ObjectByVal e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs)  
        gridView.CalculateAggregates()  
    End Sub 
 

Regards,
Nic Roche
0
Stefan Dobrev
Telerik team
answered on 08 Dec 2009, 04:06 PM
Hi Nic,

You should use our latest internal build that has a fix for this. Also note that we will release a service pack release till the end of the week that will also include various fixes around automatic aggregate functions recalculation on item update.

Hope this helps.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nic Roche
Top achievements
Rank 1
answered on 08 Dec 2009, 07:15 PM
Hi Stefan,

How do I get the latest internal build?

Regards,
Nic
0
Dean
Top achievements
Rank 1
answered on 09 Dec 2009, 12:05 AM
I'm running in to this same issue.  I have a DataTable I'm getting from a SQL query and I want to programmatically add a SumFunction to a Decimal field (should just work, right?) and I'm getting an exception.  I'm trying downloading the latest internal build from here:

http://www.telerik.com/account/downloads/internal-builds.aspx
0
Nic Roche
Top achievements
Rank 1
answered on 09 Dec 2009, 12:33 AM
Thanks Dean,

That page shows:
No internal builds for your products have been uploaded recently.

If this is the case, we are already using the latest internal build and it does not resolve the problem.


> (should just work, right?)

right. at this stage I am open to a workaround if need be...
0
Dean
Top achievements
Rank 1
answered on 09 Dec 2009, 12:50 AM
Oh... I think that means you don't have the RadControls for WPF registered in your account as a "product" or something along those lines (but I have no clue and only Telerik can answer that question).  I'm still in the trial period of RadControls (dealing with issues like this to make sure they will work for me before we buy them) so I did the following to get the internal build:

1. Went to this link: http://www.telerik.com/products/wpf.aspx
2. Clicked on "Download Trial"
2. Clicked on "Latest internal trial builds"

That might work... not sure.


Anyway, once I was up and running on the latest internal build I saw that new property and was able to use it to get things working.  You should be able to do it with something like this:

GridViewDataColumn myColumn = new GridViewDataColumn();  
SumFunction myDecimalSum = new SumFunction();  
myDecimalSum.Caption = "Sum: ";  
myDecimalSum.SourceFieldType = typeof(decimal);  
myDecimalSum.SourceField = "NameOfYourDataField";  
myColumn.AggregateFunctions.Add(decSum); 

If you don't see that property you're not on the latest build.
Tags
GridView
Asked by
Nic Roche
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Nic Roche
Top achievements
Rank 1
Dean
Top achievements
Rank 1
Share this question
or