Edit this page

Get aggregates from a group

This article shows how to obtain aggregates from a specific group in RadGridView.

In some cases when you define aggregates in RadGridView you need to access aggregates in a specific group. You may do this very easily through iterating over the groups in RadGridView check for a specific group key value and get the aggregate result as shown below:

private void Button1_Click(object sender, RoutedEventArgs e)
{
    foreach (QueryableCollectionViewGroup item in this.radGridView.Items.Groups)
    {
        if (item.Key.Equals("24"))
        {
            MessageBox.Show(item.AggregateResults[0].FormattedValue.ToString());
        }
    }
}
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    For Each item As QueryableCollectionViewGroup In Me.radGridView.Items.Groups
        If (item.Key.Equals("24")) Then
            MessageBox.Show(item.AggregateResults(0).FormattedValue.ToString())
        End If
    Next
End Sub

The QueryableCollectionViewGroup class represents a wrapper over an AggregateFunctionsGroup that allows adding and removing of child items/groups. The snippet above simply checks for a key value equal to 24 and gets the formatted value of the first aggregate result.