)
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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How To Hide Subtotals in the PivotGridControl Programmatically

Platform: WPF |
Control: PivotGridControl |
Published Date: November 26, 2014 |
Last Revised Date: November 26, 2014
Tags: general, wpf

To Show/Hide the subtotals we can normally make use of ShowSubTotal property value. By setting the property value to true or false, we can show/Hide subtotals value.

This can also be achieved by programmatically without the property value incase if u don’t use that property. The following program explains the above mentioned issue.

Code Snippet to Hide the Row subtotals:

C#

 

 

 

C:\Users\labuser\Dropbox\Screenshots\Screenshot 2014-05-22 15.20.05.png

Figure: PivotGrid shows Row subtotals hidden

 

Code Snippet to Hide Column Subtotals:

int row, column;

PivotCellInfo cellInfo = null;

for (column = this.pivotGrid1.PivotEngine.PivotRows.Count; column < this.pivotGrid1.PivotEngine.ColumnCount; column++)

{

for (row = 0; row < this.pivotGrid1.PivotEngine.PivotColumns.Count - 1; row++)

{

cellInfo = this.pivotGrid1.PivotEngine[row, column];

if (cellInfo != null)

{

if (cellInfo.CellType.ToString().Contains("TotalCell") && !cellInfo.CellType.ToString().Contains("Grand"))

{

if (this.ShowColumnTotal.IsChecked.HasValue )

if( !this.ShowColumnTotal.IsChecked.Value)

this.pivotGrid1.InternalGrid.Model.ColumnWidths.SetHidden(column, column + this.pivotGrid1.PivotCalculations.Count, true); //Specified Column will be hidden

else

this.pivotGrid1.InternalGrid.Model.ColumnWidths.SetHidden(column, column + this.pivotGrid1.PivotCalculations.Count, false); //Specified Column will be shown

}

}

}

}

this.pivotGrid1.InternalGrid.InvalidateCells();

}

 

 

C:\Users\labuser\Dropbox\Screenshots\Screenshot 2014-05-22 15.24.27.png

                                             Figure: PivotGrid shows column subtotals hidden

 

Code Snippet to Hide the Row and Column Subtotals at the Initial Loading:

C#

public MainWindow()

{

InitializeComponent();

this.pivotGrid1.Loaded += (s, a) =>

{

this.pivotGrid1.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action(() =>

{

HideSubtotals();

}));

};

}

void HideSubtotals()

{

int row, column;

PivotCellInfo cellInfo = null;

if (this.pivotGrid1.PivotEngine != null)

{

for (row = this.pivotGrid1.PivotEngine.PivotColumns.Count + (!this.pivotGrid1.PivotEngine.ShowCalculationsAsColumns ? 1 : 0); row < this.pivotGrid1.PivotEngine.RowCount; row++)

{

for (column = 0; column < this.pivotGrid1.PivotEngine.PivotRows.Count - 1; column++)

{

cellInfo = this.pivotGrid1.PivotEngine[row, column];

if (cellInfo != null)

{

if (cellInfo.CellType.ToString().Contains("TotalCell") && !cellInfo.CellType.ToString().Contains("Grand"))

{

this.pivotGrid1.InternalGrid.Model.RowHeights.SetHidden(row, row, true);

}

}

}

}

for (column = this.pivotGrid1.PivotEngine.PivotRows.Count; column < this.pivotGrid1.PivotEngine.ColumnCount; column++)

{

for (row = 0; row < this.pivotGrid1.PivotEngine.PivotColumns.Count - 1; row++)

{

cellInfo = this.pivotGrid1.PivotEngine[row, column];

if (cellInfo != null)

{

if (cellInfo.CellType.ToString().Contains("TotalCell") && !cellInfo.CellType.ToString().Contains("Grand"))

{

this.pivotGrid1.InternalGrid.Model.ColumnWidths.SetHidden(column, column + this.pivotGrid1.PivotCalculations.Count, true);

}

}

}

}

 

 

2X faster development

The ultimate WPF 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
Live Chat Icon