Articles in this section
Category / Section

How to change the WinForms GridGroupingControl text in GroupHeader and GroupFooter?

2 mins read

Change the text

When loading the GridGroupingControl, the values of the header or footer will not be displayed because grid's underlying data source doesn't maintain the data of these headers and footer. So, we need to manually populate/show the values of GroupHeaders or Footers.


To show the GroupHeaders or GroupFooters, ShowGroupHeader and ShowGroupFooter properties will be used. QueryCellInfo event is used to display the needed text on these header/footer cells. The modified cell text can be retrieved through 'CurrentCellControlLostFocus' event.


In the given code sample, the global variables 'header' and 'footer' will be used to retrieve or display the content using QueryCellInfo and CurrentCellControlLostFocus events.


this.gridGroupingControl1.TopLevelGroupOptions.ShowGroupHeader = true;
this.gridGroupingControl1.TopLevelGroupOptions.ShowGroupFooter = true;
this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
this.gridGroupingControl1.TableControl.CurrentCellControlLostFocus += TableControl_CurrentCellControlLostFocus;
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
    //assigning the GroupHeader text
    if(e.TableCellIdentity.TableCellType== GridTableCellType.GroupHeaderSectionCell )
        e.Style.Text = header;
    //assigning the GroupFooter text
    else if(e.TableCellIdentity.TableCellType == GridTableCellType.GroupFooterSectionCell)
        e.Style.Text = footer;
void TableControl_CurrentCellControlLostFocus(object sender, ControlEventArgs e)
   GridTableControl table = (sender as GridTableControl);
    GridTableCellStyleInfo style = table.GetTableViewStyleInfo(table.CurrentCell.RowIndex, table.CurrentCell.ColIndex);
   //save the header text
    if (style.TableCellIdentity.TableCellType == GridTableCellType.GroupHeaderSectionCell)
        header = e.Control.Text;
    //save the footer text
    else if (style.TableCellIdentity.TableCellType == GridTableCellType.GroupFooterSectionCell)
        footer = e.Control.Text;


Me.gridGroupingControl1.TopLevelGroupOptions.ShowGroupHeader = True
Me.gridGroupingControl1.TopLevelGroupOptions.ShowGroupFooter = True
AddHandler gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
AddHandler Me.gridGroupingControl1.TableControl.CurrentCellControlLostFocus, AddressOf TableControl_CurrentCellControlLostFocus
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
    ‘assigning the GroupHeader text
    If e.TableCellIdentity.TableCellType= GridTableCellType.GroupHeaderSectionCell Then
          e.Style.Text = header
    ‘assigning the GroupFooter text
    ElseIf e.TableCellIdentity.TableCellType = GridTableCellType.GroupFooterSectionCell    Then
           e.Style.Text = footer
    End If
End Sub
Private Sub TableControl_CurrentCellControlLostFocus(ByVal sender As Object, ByVal e As ControlEventArgs)
    Dim table As GridTableControl = (TryCast(sender, GridTableControl))
    Dim style As GridTableCellStyleInfo = table.GetTableViewStyleInfo(table.CurrentCell.RowIndex, table.CurrentCell.ColIndex)
    ‘save the header text
    If style.TableCellIdentity.TableCellType = GridTableCellType.GroupHeaderSectionCell Then
        header = e.Control.Text
    ‘save the footer text
    ElseIf style.TableCellIdentity.TableCellType = GridTableCellType.GroupFooterSectionCell Then
        footer = e.Control.Text
    End If
End Sub



Show header and footer in GridGroupingControl


Change the text in header and footer

Reference link:

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied