Category / Section
How to customize the grand total header of row and column in WinForms PivotGrid control?
2 mins read
Customizing grand total header of rows
You can customize the grand total header of a row by using the FormattedText property of the row’s grand total cell.
Refer to the following code sample to customize the grand total header of a row as the “Total” instead of the “Grand Total”.
C#
for (int row = this.pivotGridControl1.PivotEngine.RowCount - 1; row >= 0; row--) { PivotCellInfo cellInfo = this.pivotGridControl1.PivotEngine[row, 0]; if (cellInfo != null && cellInfo.FormattedText != null && cellInfo.CellType == (PivotCellType.RowHeaderCell | PivotCellType.GrandTotalCell)) { cellInfo.FormattedText = "Total"; break; } }
VB
For row As Integer = Me.pivotGridControl1.PivotEngine.RowCount - 1 To 0 Step -1 Dim cellInfo As PivotCellInfo = Me.pivotGridControl1.PivotEngine(row, 0) If cellInfo IsNot Nothing AndAlso cellInfo.FormattedText IsNot Nothing AndAlso cellInfo.CellType Is (PivotCellType.RowHeaderCell Or PivotCellType.GrandTotalCell) Then cellInfo.FormattedText = "Total" Exit For End If Next row
Pivot grid rendered with customized row grand total header
Customizing grand total header of columns
You can customize the grand total header of a column by using the FormattedText property of the column’s grand total cell.
Refer to the following code sample to customize the grand total header of column as the “Total” instead of “Grand Total”.
C#
for (int column = this.pivotGridControl1.PivotEngine.ColumnCount - 1; column >= 0; column--) { PivotCellInfo cellInfo = this.pivotGridControl1.PivotEngine[0, column]; if (cellInfo != null && cellInfo.FormattedText != null && cellInfo.CellType == (PivotCellType.ColumnHeaderCell | PivotCellType.GrandTotalCell)) { cellInfo.FormattedText = "Total"; break; } }
VB
For column As Integer = Me.pivotGridControl1.PivotEngine.ColumnCount - 1 To 0 Step -1 Dim cellInfo As PivotCellInfo = Me.pivotGridControl1.PivotEngine(0, column) If cellInfo IsNot Nothing AndAlso cellInfo.FormattedText IsNot Nothing AndAlso cellInfo.CellType Is (PivotCellType.ColumnHeaderCell Or PivotCellType.GrandTotalCell) Then cellInfo.FormattedText = "Total" Exit For End If Next column
Pivot grid rendered with customized column grand total header