$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView for Windows Forms
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > Summary Rows in C#

Summary Grid Rows of C# DataGridView

The summary grid rows of DataGridView C#.NET Component allow users to display information of the data containing in the GridView like first item, last item, count of items, and more for Windows Forms applications. The DataGridView control will pin the summary grid rows to top and bottom to the grid view in the C# Windows Forms application. The summary grid rows are mainly used in a flat DataGridView or in groups and hierarchical views for C# Windows Forms application.

How to Create Summary Rows in C#

The DataGridView control will pin the summary grid rows to top and bottom to the grid view in the C# Windows Forms application. The following is a basic example that shows how to create a summary pinned to top of the GirdView and display the count of the Kettic DataGridView rows.

GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "ProductName";
summaryItem.Aggregate = GridAggregateFunction.Count;

GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);

this.ketticGridView.SummaryRowsTop.Add(summaryRowItem);
this.ketticGridView.SummaryRowsBottom.Add(summaryRowItem);

Porperties of SummaryItem

The DataGridView control offers the Summary item to customize the summary item. And the major properties of the DataGridView control include as below:
  • Name, this is the property used to refer to the name of the column by summary item.
  • Aggregate, the property is used to evaluate the function. And the predefined aggregates contain None, Sum, Min, Max, Last, First, Count, Avg, StDev, and Var.
  • AggregateExpression, this property is the final expression to evaluate.
  • FormatString, the property is used to apply formatting string to the calculated value of the summary item.

How to Use the FormatString in C#

The C# code sample below shows how to add several summary items in a summary gird row and how to use the FormatString to DataGridView.

GridViewSummaryItem summaryItemShipName = new GridViewSummaryItem("ProductName", "{0}", GridAggregateFunction.Last);
GridViewSummaryItem summaryItemFreight = new GridViewSummaryItem("Freight", "Max Freight = {0}", GridAggregateFunction.Max);

GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem(
new GridViewSummaryItem[] { summaryItemShipName, summaryItemFreight });

this.ketticGridView1.SummaryRowsTop.Add(summaryRowItem);

How to Use AggregateExpression in C#

The C# code sample below shows how to use AggregateExpression to calculate an average value excluding the Max and Min value to DataGridView.


GridViewSummaryItem summaryItem = new GridViewSummaryItem();
summaryItem.Name = "Freight";
summaryItem.AggregateExpression = "(Sum(Freight) - Max(Freight) - Min(Freight)) / Count(Freight)";

GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);
this.ketticGridView.SummaryRowsTop.Add(summaryRowItem);

Grouped GridView Summary Rows

The Summary grid rows is able to calculate each group child rows and display them to top or bottom in each group GridView when you use grouping. The GridView component offers the DisplayTotals property to determine whether displaying the total summary rows or not. The summary rows will calculate all the child rows of the groups and pin them to top and bottom to the grouped GridView. The C# code sample below shows how to use summary rows in grouped GridView.

this.ketticGridView.MasterTemplate.DisplayTotals = true;

GridViewSummaryItem summaryItem = new GridViewSummaryItem("Freight", "{0}", GridAggregateFunction.Max);
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);

this.ketticGridView.SummaryRowsTop.Add(summaryRowItem);

Hierarchical GridView Summary Rows

The Kettic GridView control allows users to add summary gird rows in hierarchical views. And the summary grid rows will be calculated for the child grid rows in the current view. The C# code sample below shows how to add a summary row to the first level of Kettic GridView hierarchy.

GridViewSummaryItem summaryItem = new GridViewSummaryItem("Quantity", "Max quantity = {0}", GridAggregateFunction.Max);
GridViewSummaryRowItem summaryRowItem = new GridViewSummaryRowItem();
summaryRowItem.Add(summaryItem);

this.ketticGridView.MasterTemplate.Templates[0].SummaryRowsTop.Add(summaryRowItem);


UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls