Custom aggregate functions

2 posts, 0 answers
  1. Stavroula
    Stavroula avatar
    5 posts
    Member since:
    Sep 2011

    Posted 07 Nov 2011 Link to this post

    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?

     

  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Nov 2011 Link to this post

    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 >>

Back to Top