# MainWindow.Xaml <Window.Resources> <DataTemplate x:Key="CustomSummaryTemplate"> <Border Name="Border" Background="Green" BorderBrush="#888" BorderThickness="1" CornerRadius="4"> <TextBlock Text="{Binding Path=CellValue}" Padding="2" /> </Border> </DataTemplate> </Window.Resources> |
# MainWindow.Xaml.cs private void PivotGrid1_Loaded(object sender, RoutedEventArgs e) { pivotGrid1.InternalGrid.QueryCellInfo += InternalGrid_QueryCellInfo; } private void InternalGrid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) { int startIndex = pivotGrid1.PivotColumns.Count + (pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0); if (pivotGrid1.PivotEngine[e.Cell.RowIndex,e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") && pivotGrid1.PivotCalculations.Any(col => col.FieldName == pivotGrid1.PivotEngine[startIndex - 1,e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom)) { DataTemplate dt = this.Resources["CustomSummaryTemplate"] as DataTemplate; pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellItemTemplate = dt; pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].Background = new SolidColorBrush(Colors.Gray); pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].Foreground = new SolidColorBrush(Colors.Red); e.Handled = true; } } |
CellItemTemplate is not applied (Background and Foreground works fine).. | In order to apply the cell template for value cells, you need to set the CellType of current cell as “DataBoundTemplate”. We are extremely sorry for missing to mentioned that in our previous update. We have modified the attached sample based on your requirement and please find the sample from the following location. Please refer to following code example.
| ||
In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents? | As per the default behavior of PivotGrid control, InternalGrid for PivotGrid control has been rendered once the PivotGrid control was loaded. If you are trying to access the InternalGrid of PivotGrid control in loaded event handler of either Window or any other controls, it throws an exception as InternalGrid is null. So before access the InternalGrid, you must invoke/hook the loaded event of PivotGrid control and make sure that the control was rendered properly. Then you can access the InternalGrid within the PivotGrid_Loaded() event handler method. We had reviewed the video attached in your previous update and we suspect that the PivotGrid control was not loaded properly. Could you please ensure that the PivotGrid control was rendered properly within the controls (Docking Manager, Window, etc.,)? If possible, can you share your working sample with us, so that it would be helpful for us to check the same. |
In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents? | I found the problem. I show the pivotGridControl just when it contains some data. So at the begining it didn't contain any data, so the visibility was set to Collapsed. |
One more question about QueryCellInfo.. | Is it possible to change in QueryCellInfo just text-foreground? Like: .. int startIndex = pivotGrid1.PivotColumns.Count +
(pivotGrid1.PivotCalculations.Count > 1 ? 1 : 0); if
(pivotGrid1.PivotEngine[e.Cell.RowIndex,e.Cell.ColumnIndex].CellType.ToString().Contains("ValueCell") && pivotGrid1.PivotCalculations.Any(col
=> col.FieldName == pivotGrid1.PivotEngine[startIndex -
1,e.Cell.ColumnIndex].FormattedText && col.SummaryType == SummaryType.Custom)) {
pivotGrid1.InternalGrid.Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellValue
= pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; pivotGrid1.InternalGrid.Model[e.Cell.RowIndex,
e.Cell.ColumnIndex].Foreground = new SolidColorBrush(Colors.Red); e.Handled = true; } |
One more question about QueryCellInfo.. | If you are try to set any style attribute for cell values, the entire style attributes for corresponding cell are also changing respectively. Since the CellType of the cell has been changed as “Static” and also the default style was applied as per the behavior of our base Grid control. We have set the CellType as “TemplateCell” for value cells and customizing the styles for accordingly while rendering the values into the cells. So if you want to change any style attribute for particular cell, you must customize all the style attributes based on the style applied for either value cells or summary cells. Please find the attached sample from the following location. Please refer to the following code example.
| |
In my application in 'Loaded' event is pivotGrid.InternalGrid == null. Maybe this is because I'm using DockingManager (with document-container) and dynamically created documents? | Could you please confirm us whether the problem was resolved from your side and let us know if you require further assistance on this? |