Articles in this section

How to customize the group caption text in WinForms GridGroupingControl?

Customize the group caption


By default, the grouped columns cell value will be displayed without any formatting in GroupCaptionRow in WinForms GridGroupingControl.

 

Solution

To change the GroupCaptionText, use the QueryCellStyleInfo event to change the cell value using TableCellIdentity.

 

C#

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{            
    if (e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell && e.TableCellIdentity.GroupedColumn != null)
    {
        GridCaptionRow captionRow = e.TableCellIdentity.DisplayElement as GridCaptionRow;
        string date = "";
        DateTime dt;
        if (e.Style.Text != null && DateTime.TryParse(e.Style.Text.Substring(e.Style.Text.IndexOf(":") + 1, 8), out dt))
        {
            date = dt.ToString("MMM-yyyy");
        }
        e.Style.CellValue = String.Format("{0}: {1} Items.", date, e.TableCellIdentity.DisplayElement.ParentGroup.GetChildCount());
    }
}

VB

Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
    If e.TableCellIdentity.TableCellType = GridTableCellType.GroupCaptionCell AndAlso e.TableCellIdentity.GroupedColumn IsNot Nothing Then
        Dim captionRow As GridCaptionRow = TryCast(e.TableCellIdentity.DisplayElement, GridCaptionRow)
        Dim [date] As String = ""
        Dim dt As DateTime
        If e.Style.Text IsNot Nothing AndAlso DateTime.TryParse(e.Style.Text.Substring(e.Style.Text.IndexOf(":") + 1, 8), dt) Then
            [date] = dt.ToString("MMM-yyyy")
        End If
        e.Style.CellValue = [String].Format("{0}: {1} Items.", [date], e.TableCellIdentity.DisplayElement.ParentGroup.GetChildCount())
    End If
End Sub
Customizing caption text as shown in the screenshot below,

Customize the group caption text

Samples:

C#: CustomGroupCaptionText

VBCustomGroupCaptionText


Reference Link: 
Customizing CaptionText

 

Conclusion


I hope you enjoyed learning about how to customize the group caption text in GridGroupingControl.


You can refer to our  WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied