PivotGridControl - Change "Grand" totals header text?

Good day,

Is it possible to change the header text of the Grand Totals rows/columns to something like "Total"?

Also, is there a way to ignore the Grand totals rows / columns when selecting a range? I have it set up  to where a pre-determined range is selected as it loops through a filter list. A problem I have run into is even when the totals rows /cols are hidden they are still actually present and they are selected when a filter item does not include all of the original columns or rows.

3 Replies

TB Thirupathi Bala Krishnan Syncfusion Team July 27, 2018 09:18 AM UTC

Hi Travis, 
 
Please find our response as below: 
 
S.No. 
Query 
Description 
1. 
Is it possible to change the header text of the Grand Totals rows/columns to something like "Total"? 
Yes. You can customize the grand total string header values by replacing the custom values into the ‘FormattedText’ property of PivotCellInfo.  
 
Please refer the below code snippet: 
 
#Form1.cs 
 
        public Form1() 
        { 
            InitializeComponent(); 
            this.InitializePivotGrid(); 
 
            //Customize the row grand total string value. 
            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; 
                } 
            } 
            //Customize column grand total string value. 
            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; 
                } 
            } 
        } 
 
 
2. 
Also, is there a way to ignore the Grand totals rows / columns when selecting a range? I have it set up  to where a pre-determined range is selected as it loops through a filter list. A problem I have run into is even when the totals rows /cols are hidden they are still actually present and they are selected when a filter item does not include all of the original columns or rows. 
Yes. You can enable/disable the grand total rows and columns by using the ‘ShowGrandTotals’ property of PivotEngine. If you want to ignore the grand totals rows/columns while selecting the ranges, you can skip your operation by checking the condition if the cell type is grand total cell. 
 
Please refer the below code snippet: 
 
#Form1.cs 
 
        public Form1() 
        { 
            InitializeComponent(); 
            this.InitializePivotGrid(); 
 
            //To hide the grand totals. 
            this.pivotGridControl1.PivotEngine.ShowGrandTotals = false; 
            this.pivotGridControl1.TableControl.Model.SelectionChanged += Model_SelectionChanged; 
        } 
 
        private void Model_SelectionChanged(object sender, GridSelectionChangedEventArgs e) 
        { 
            bool allowSelection = e.Range.ToString().Contains(":"); 
            if (allowSelection) 
            { 
                for (int row = e.Range.Top; row <= e.Range.Bottom; row++) 
                { 
                    for (int column = e.Range.Left; column <= e.Range.Right; column++) 
                    { 
                        PivotCellInfo cellInfo = this.pivotGridControl1.PivotEngine[row - 1, column - 1]; 
                       if (cellInfo != null && cellInfo.FormattedText != null &&                   cellInfo.CellType.ToString().Contains("GrandTotal")) 
                        { 
                            //to restrict the cell selection for grand total rows/columns.             
                            this.pivotGridControl1.TableModel.Selections.Clear(); 
                        } 
                    } 
                } 
            } 
        } 
 
 
 
Please find our working sample from the following location: 
 
If the above solution does not meet your actual requirement, could you please share the detailed description about your requirement, it would be helpful to provide the solution at the earliest. 
 
Regards, 
Thirupathi B. 
 



TC Travis Chambers July 28, 2018 04:04 AM UTC

Thank you for your quick response.

I am having an issue with the avoiding the totals row in my selections.

I am getting a rowindex out of range error at

"PivotCellInfo cellInfo = PG.PivotEngine[row-1, column-1];"


Thanks.



TB Thirupathi Bala Krishnan Syncfusion Team July 30, 2018 09:40 AM UTC

Hi Travis, 

We are unable to reproduce the reported issue –“Argument out of range exception thrown while selecting the grand total cells in pivot grid”. Could you please share captured video with reported issue and also define the number of PivotRows, PivotColumns and PivotCalculations that are used in your application. Otherwise, please modify the attached the sample in order to reproduce the reported issue, it would be helpful to provide the solution at the earliest. 

Please find our working demo and sample from the following location: 

Regards, 
Thirupathi B. 


Loader.
Up arrow icon