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

Adding a Column and Aggregate Programatically

2 Answers 25 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 22 Jan 2014, 12:50 AM
I am adding columns to a grid programmatically as the number of columns can vary.  Additionally I want to sum the column values in the column footer.  The following code is used to achieve this;

Private Sub AddContractYearColumns()
    Dim sPeriod As String = String.Empty
    Dim iIndex As Integer = 0
 
    Try
        Dim Years = From Yrs In gdcRAD.vw_ProjectYears Select Yrs.Year
 
        For Each Yr As String In Years
            If Yr.ToInteger >= Year(Date.Today) Then
                iIndex += 1
                sPeriod = "Period" & iIndex.ToString("00")
 
                Dim column As New GridViewDataColumn()
 
                With column
                    .Header = Yr
                    .UniqueName = Yr
                    .DataMemberBinding = New Binding(sPeriod)
                    .DataFormatString = "0.00"
                    .TextAlignment = TextAlignment.Right
                End With
 
                gvContractYrs.Columns.Add(column)
 
                Dim f As New Telerik.Windows.Data.SumFunction
                f.SourceField = sPeriod
                gvContractYrs.Columns(Yr).AggregateFunctions.Add(f)
            End If
        Next
    Catch ex As Exception
        Throw New RadException("Add Contract Year Columns", ex.Message, ex.InnerException)
    End Try
End Sub

This creates columns with headings such as "2014", "2015", etc that are bound to "Period01", "Period02", etc.

The following code is then used to to obtain and bind the data to the grid;

Private Sub DisplayAvailableEquipYrs()
    Try
        Dim EquipList = (From Equipment In gdcRAD.usp_YearsAvailable(Date.Today, False, False) Select Equipment).ToList
        gvContractYrs.ItemsSource = EquipList
 
    Catch ex As Exception
        Throw New RadException("Display Available Equipment Years", ex.Message, ex.InnerException)
    End Try
End Sub

The EquipList is populated correctly with a nullable Double data type being returned for "Period01", "Period02", etc however I get the error "No generic method 'Sum' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments." when I attempt to bind the EquipList object to the ItemsSource.

Could the nullable data type be causing the problem?

2 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 23 Jan 2014, 04:27 AM
Anyone?
0
Yoan
Telerik team
answered on 23 Jan 2014, 08:57 AM
Hi Raymond,

Generally, you can sum only Numeric types. Please check this troubleshooting article for a reference.

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 >>
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or