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

custom aggregate functions and grouping

7 Answers 425 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tomer
Top achievements
Rank 1
Tomer asked on 05 Jan 2011, 02:38 PM
Hi,
i'm having trouble with creating custom aggregate function for the WinForms grid, all i see is the AggregateExpression property that lets me do basic stuff like dividing and multiplying built-in aggregate functions, but what i need is a custom way to calculate stuff, i did this with the asp.net grid, but the winforms seems to work different.

your online help has some conflicts, there is a place where it specifically tells you to create a class like that:
Public Class CustomSummaryItem
    Inherits GridViewSummaryItem
but when i try to do this the GridViewSummaryItem has no virtual/abstract method:
Public Overrides Function Evaluate(ByVal row As IHierarchicalRow) As Object

please help me out, Thanks.

i have 2010.2.10.914 version.


7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 05 Jan 2011, 08:58 PM
Hi Tomar,

As far as i'm aware, there is no conflict in the documentation. The issue is that the documentation is for the latest Q3 2010 SP1 version,  and you are using an older version.

If you can let me know your requirement I will do my best to help, but I am also using the latest version.
Regards,
Richard
0
Tomer
Top achievements
Rank 1
answered on 06 Jan 2011, 08:09 AM
Hi,
well i thought i did explain what i was trying to achieve...
i want to be able to have a custom aggregation function, like sum or avg, i need Yield which is count pass divided by the total pass and fail, the problem is when there are no item this causes a divide by zero and i need to control the precision, the rounding off to 2 digits after the decimal point.

i did manage to do this with the ASP.NET radgrid...
Thanks.
0
Richard Slade
Top achievements
Rank 2
answered on 06 Jan 2011, 11:12 AM
Hello Tomar,

I'm afraid I cannot provide you with an exmaple that I know will work in your version, but I have put together a quick sample with the version that I have in the hope that it might help.
Imports Telerik.WinControls.UI
  
Public Class Form1
  
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim exams As New List(Of Exam)
        exams.Add(New Exam("English", True))
        exams.Add(New Exam("Maths", True))
        exams.Add(New Exam("Biology", False))
        exams.Add(New Exam("IT", True))
        exams.Add(New Exam("RE", False))
  
        Me.RadGridView1.DataSource = exams
  
        AddHandler RadGridView1.GroupSummaryEvaluate, AddressOf RadGridView1_GroupSummaryEvaluate
  
        Dim summaryItem As New CustomSummaryItem("Pass", "{0}", GridAggregateFunction.Count)
        Dim summaryRowItem As New GridViewSummaryRowItem()
        summaryRowItem.Add(summaryItem)
  
        Me.RadGridView1.SummaryRowsBottom.Add(summaryRowItem)
  
    End Sub
  
    Private Sub RadGridView1_GroupSummaryEvaluate(ByVal sender As Object, ByVal e As GroupSummaryEvaluationEventArgs)
        If e.Parent Is Me.RadGridView1.MasterTemplate Then
            e.FormatString = String.Format("Pass rate is {0}%", e.Value)
        End If
    End Sub
  
End Class
  
Public Class CustomSummaryItem
    Inherits GridViewSummaryItem
  
    Public Sub New(ByVal name As String, ByVal formatString As String, ByVal aggregate As GridAggregateFunction)
        MyBase.New(name, formatString, aggregate)
    End Sub
  
    Public Overrides Function Evaluate(ByVal row As IHierarchicalRow) As Object
        Dim passes As Integer
        Dim rows As Integer
        For Each childRow As GridViewRowInfo In row.ChildRows
            If CBool(childRow.Cells("Pass").Value) = True Then
                passes += 1
            End If
            rows += 1
        Next childRow
  
        Return (passes / rows) * 100
    End Function
End Class
  
Public Class Exam
    Public Sub New(ByVal name As String, ByVal pass As Boolean)
        Me.Name = name
        Me.Pass = pass
    End Sub
  
    Public Property Name As String
    Public Property Pass As Boolean
End Class

Regards,
Richard
0
Tomer
Top achievements
Rank 1
answered on 06 Jan 2011, 12:04 PM
Thank you for the quick and extensive replay.
unfortunately in my version of the product i can't inherit  from GridViewSummaryItem...
i have version 2010.2.10.914.
where do i find the class i need to override the Evaluate method in?
0
Richard Slade
Top achievements
Rank 2
answered on 06 Jan 2011, 12:47 PM
Hi Again Tomer

Have a look at this forum thread. I had remembered that someone else wanted a Yield in the summary item and the post gives a solution using only GroupSummaryEvaluate.

Hope that helps
Richard
0
Tomer
Top achievements
Rank 1
answered on 06 Jan 2011, 01:29 PM
Thanks, i'll have a look.
0
Alexander
Telerik team
answered on 07 Jan 2011, 12:40 PM
Hello Tomer,

You can create custom summary items evaluation using the GroupSummaryEvaluate event of RadGridView or the CustomSummaryItem. The approach for creating a custom SummaryItem and overriding the Evaluate method is introduced in the latest version of the control. You can use the GroupSummaryEvaluate event with your version of RadGridView. The Parent property of its event arguments, used in the example given in the thread which Richard has pointed, is introduced in the latest version of the control.

Please let us know if we can assist you further.

Best regards,
Alexander
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
GridView
Asked by
Tomer
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Tomer
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or