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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How To Hide Subtotals in the PivotGridControl Programmatically

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);

}

}

}

}

 

 

Article ID: Published Date: Last Revised Date: Platform: Control:
2933 11/26/2014 11/26/2014 WPF PivotGridControl
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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