New to Telerik UI for WinForms? Download free 30-day trial

Formatting Group Header Row

GroupSummaryEvaluate allows to modify the header text of the group rows. The event is fired when the group header row text is needed. So if you want to modify the group’s text, first you have to subscribe to the GroupSummaryEvaluate event and then perform the actual grouping, because when the GroupContentCellElement (the group header row) is being displayed, the event is fired and if you are not subscribed for it, it will apply its default settings.

The example below demonstrates how you can change the group header text of each group if grouping is based on some specific column:

Change group header text

void radGridView1_GroupSummaryEvaluate(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
    if (e.SummaryItem.Name == "Country")
    {
        e.FormatString = String.Format("Group by country: {0}", e.Value);
    }
}

Private Sub RadGridView1_GroupSummaryEvaluate(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs) Handles RadGridView1.GroupSummaryEvaluate
    If e.SummaryItem.Name = "Country" Then
        e.FormatString = [String].Format("Group by country: {0}", e.Value)
    End If
End Sub

WinForms RadGridView Change group header text

The following example demonstrates formatting of group header which uses data from the group rows:

Formatting group header by using data from data rows

void radGridView1_GroupSummaryEvaluate1(object sender, Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs e)
{
    if (e.SummaryItem.Name == "ContactTitle")
    {
        int count = e.Group.ItemCount;
        int contactsInCanada = 0;
        foreach (GridViewRowInfo row in e.Group)
        {
            if (row.Cells["Country"].Value.ToString() == "Canada")
            {
                contactsInCanada++;
            }
        }
        e.FormatString = String.Format("There are {0} {1} and {2} of them is(are) from Canada.", count, e.Value, contactsInCanada);
    }
}

Private Sub RadGridView1_GroupSummaryEvaluate1(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GroupSummaryEvaluationEventArgs) Handles RadGridView1.GroupSummaryEvaluate
    If e.SummaryItem.Name = "ContactTitle" Then
        Dim contactsCount As Integer = e.Group.ItemCount
        Dim contactsInCanada As Integer = 0
        For Each row As GridViewRowInfo In e.Group
            If row.Cells("Country").Value.ToString() = "Canada" Then
                contactsInCanada += 1
            End If
        Next
        e.FormatString = [String].Format("There are {0} {1} and {2} of them is(are) from France.", contactsCount, e.Value, contactsInCanada)
    End If
End Sub

WinForms RadGridView Formatting group header

See Also

In this article