We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to freeze the summary row at bottom of the grid in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl
Tags: summaries

Summaries

By default, the GridGroupingControl does not have support to freeze a summary row. To achieve place a single row at the bottom of the grid and set the calculated summary values to that grid cell which acts as a summary row.

GridControl customization

CS

public class EngineSummaryGrid
 {
     private GridControl grid;
     private GridGroupingControl parentGrid;
 
     public void WiredSummary(GridGroupingControl ggc)
     {
         parentGrid = ggc;
         parentGrid.TopLevelGroupOptions.ShowSummaries = false;
         parentGrid.TableModel.QueryColWidth += TableModel_QueryColWidth;
         parentGrid.TableControl.Layout += TableControl_Layout;
         //Initializing the grid with single row.
         grid = new GridControl();
         grid.ThemesEnabled = true;
         grid.Model.Options.NumberedRowHeaders = false;
         grid.Model.RowCount = 1;
         this.grid.Model.ColCount = this.parentGrid.TableDescriptor.Columns.Count;
         grid.Properties.ColHeaders = false;           
         ggc.TableControl.Controls.Add(grid);
         SetSummary(ggc);
     }
     private void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
     {
         this.grid.Model.ColWidths[e.Index] = e.Size;
     }
     private void TableControl_Layout(object sender, LayoutEventArgs e)
     {
         SummaryRowSize();
     }
     
     private void SummaryRowSize()
     {
         parentGrid.TableControl.ResetGridBounds();
         this.parentGrid.TableControl.ResetGridBounds();
         this.parentGrid.TableControl.GridBounds = new Rectangle(this.parentGrid.TableControl.GridBounds.X,
             this.parentGrid.TableControl.GridBounds.Y, this.parentGrid.TableControl.GridBounds.Width,
             this.parentGrid.TableControl.GridBounds.Height - (this.parentGrid.TableControl.DefaultRowHeight));
         int height = this.parentGrid.TableControl.GridBounds.Height + this.parentGrid.TableControl.DefaultRowHeight;
         this.grid.Location = new Point(0, height - this.parentGrid.TableControl.DefaultRowHeight);
         this.grid.Size = new Size(this.parentGrid.TableControl.ClientSize.Width, this.parentGrid.TableControl.DefaultRowHeight);
     }
 }

 

VB

Public Class EngineSummaryGrid
     Private grid As GridControl
     Private parentGrid As GridGroupingControl
     Public Sub WiredSummary(ByVal ggc As GridGroupingControl)
         parentGrid = ggc
         parentGrid.TopLevelGroupOptions.ShowSummaries = False
         AddHandler parentGrid.TableModel.QueryColWidth, AddressOf TableModel_QueryColWidth
         AddHandler parentGrid.TableControl.Layout, AddressOf TableControl_Layout
         'Initializing the grid with single row.
         grid = New GridControl()
         grid.ThemesEnabled = True
         grid.Model.Options.NumberedRowHeaders = False
         grid.Model.RowCount = 1
         Me.grid.Model.ColCount = Me.parentGrid.TableDescriptor.Columns.Count
         grid.Properties.ColHeaders = False
         ggc.TableControl.Controls.Add(grid)
         SetSummary(ggc)
     End Sub
     Private Sub TableModel_QueryColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
         Me.grid.Model.ColWidths(e.Index) = e.Size
     End Sub
     Private Sub TableControl_Layout(ByVal sender As Object, ByVal e As LayoutEventArgs)
         SummaryRowSize()
     End Sub    
     Private Sub SummaryRowSize()
         parentGrid.TableControl.ResetGridBounds()
         Me.parentGrid.TableControl.ResetGridBounds()
         Me.parentGrid.TableControl.GridBounds = New Rectangle(Me.parentGrid.TableControl.GridBounds.X,
             Me.parentGrid.TableControl.GridBounds.Y,
             Me.parentGrid.TableControl.GridBounds.Width,
            Me.parentGrid.TableControl.GridBounds.Height - (Me.parentGrid.TableControl.DefaultRowHeight))
 
         Dim height As Integer = Me.parentGrid.TableControl.GridBounds.Height + Me.parentGrid.TableControl.DefaultRowHeight
         Me.grid.Location = New Point(0, height - Me.parentGrid.TableControl.DefaultRowHeight)
         Me.grid.Size = New Size(Me.parentGrid.TableControl.ClientSize.Width, Me.parentGrid.TableControl.DefaultRowHeight)
     End Sub
 End Class

 

Setting the Summary value to GridControl

CS

private void SetSummary(GridGroupingControl ggc)
 {
     for (int j = 0; j < grid.Model.ColCount; j++)
     {
         GridSummaryRowDescriptor row = ggc.TableDescriptor.SummaryRows[0];
         GridSummaryColumnDescriptor scd = row.GetSummaryColumnAtCol(j);
         if (scd != null)
         {
             string text = scd.GetDisplayText(ggc.Engine.Table.DisplayElements[0].ParentGroup);
             grid.Model[1, j].CellValue = row.Title;
             grid.Model[1, j + 1].CellValue = text;
             grid.Model[1, j + 1].Enabled = false;
         }
     }
 }

 

VB

Private Sub SetSummary(ByVal ggc As GridGroupingControl)
    For j As Integer = 0 To grid.Model.ColCount - 1
        Dim row As GridSummaryRowDescriptor = ggc.TableDescriptor.SummaryRows(0)
        Dim scd As GridSummaryColumnDescriptor = row.GetSummaryColumnAtCol(j)
        If scd IsNot Nothing Then
 Dim text As String = scd.GetDisplayText(ggc.Engine.Table.DisplayElements(0).ParentGroup)
 grid.Model(1, j).CellValue = row.Title
 grid.Model(1, j + 1).CellValue = text
 grid.Model(1, j + 1).Enabled = False
        End If
    Next j
End Sub

 

Adding customized grid to GridGroupingControl

CS

//To add the summary row grid to GridGrouping control
SummaryGrid = new EngineSummaryGrid();
SummaryGrid.WiredSummary(this.gridGroupingControl1);

 

VB

'To add the summary row grid to GridGrouping control 
 SummaryGrid = New EngineSummaryGrid()
 SummaryGrid.WiredSummary(Me.gridGroupingControl1)

 

Screenshot

Freeze the summary row at bottom of the grid

 

Note:

By this solution, the summary values will not be updated when modifying records in the grid.

 

Samples:

C#: Freezing SummaryRow_CS

VB: Freezing SummaryRow_VB

Reference link: https://help.syncfusion.com/windowsforms/gridgrouping/summaries

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile