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

Custom aggregate functions

1 Answer 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stavroula
Top achievements
Rank 1
Stavroula asked on 07 Nov 2011, 09:34 AM
Hallo,

I have a problem with writing a custom aggregate function. I have a Grid View, which groups the items. I can use the aggregate function to count how many items are in a group. I want to write a custom aggregate function to count how many selected items out of the existing items are there. I have an example that succeeds. But in my code comes to a Managed Runtime Error, while attempting to add the custom aggregate function to the column.
The custom function:

 

 

 

 

Imports System.Collections.Generic
Imports Telerik.Windows.Data
Namespace Views.Inverter
    Public Class CountSelectedItemsFunction
        Inherits EnumerableSelectorAggregateFunction
  
        Protected Overrides ReadOnly Property AggregateMethodName() As String
            Get
                Return "CountSelected"
            End Get
        End Property
  
        Protected Overrides ReadOnly Property ExtensionMethodsType() As Type
            Get
                Return GetType(CountSelectedItems)
            End Get
        End Property
    End Class
  
    Public NotInheritable Class CountSelectedItems
        Private Sub New()
        End Sub
  
        Public Shared Function CountSelected(Of TSource)(source As IEnumerable(Of TSource), selector As Func(Of TSource, Integer)) As Integer
            Dim itemCount As Integer = source.Count()
            Return 1
        End Function
  
    End Class
End Namespace

The error comes when this code is executed:

 

 

this.RadGridView1.Columns[1].AggregateFunctions.Add(new CountSelectedItemsFunction { SourceField = "intValue", ResultFormatString = "Int: {0}"});

I use the MVVM pattern. Could you please help me?

 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 08 Nov 2011, 09:10 AM
Hi,

 Can you post more info about the error?

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Stavroula
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or