Winforms RadGridView SummaryRowItem for selected rows

1 Answer 44 Views
GridView
Michael
Top achievements
Rank 1
Iron
Michael asked on 07 Feb 2022, 03:46 PM

Hello all.  I'm trying to figure out how to configure a summaryrow to evaluate only the selected rows when multiple rows are selected.  The evaluation event handler would need to fire and update the summary total each time the selected rows collection changes.  So far I have not been able to find any examples of this behavior.  A point in the right direction will be appreciated. 

I have tried working with the "CustomSummaryItem" from the forum but this only fires the evaluation event once and doesn't summarize changing selections- it only evaluates the first row in the grid.  I have this small bit of code posted below and my alteration is in bold.  I suspect I need to subscribe to some other (less documented) method.

Thanks in advance - Mike

I found this class in the forum ----------------------------------

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 itemsummary As Decimal = 0
        For Each childRow As GridViewRowInfo In row.ChildRows
            If childRow.IsSelected Then
                itemsummary += CDec(childRow.Cells("miles_driven").Value)
            End If
        Next childRow
        Return itemsummary
    End Function

End Class

1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 10 Feb 2022, 11:28 AM

Hi Michael,

Thank you for the provided code snippet.

You can try forcing the GridViewSummaryRowInfo to update when the selection is changed. For example, you can subscribe to the SelectionChanged event of the RadGridView. Inside the event handler, you can get the GridViewSummaryRowInfo and call its InvalidateRow() method.

Private Sub RadGridView1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
    radGridView1.MasterView.SummaryRows(0).InvalidateRow()
End Sub

Give this approach a try and let me know if it works in your application.

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Iron
Answers by
Dinko
Telerik team
Share this question
or