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.
Unfortunately, activation email could not send to your email. Please try again.

Cell Template

Thread ID:

Created:

Updated:

Platform:

Replies:

127796 Dec 9,2016 04:43 AM Dec 23,2016 12:35 AM WPF 9
loading
Tags: PivotGridControl
Juraj Tomana
Asked On December 9, 2016 04:43 AM

Hi.

It's possible to apply cell-template on CustomSummary values?

Thanks.
Regards,
Juraj

Sabaridass Ramamoorthy [Syncfusion]
Replied On December 13, 2016 06:15 AM

Hi Juraj, 
  
No. We do not have the support to apply cell-template for particular value cells. You can apply the cell template for entire value cells by using ValueCellStyle of PivotGrid control. And also you can apply the style for particular value cell by using QueryCellInfo event handler available in InternalGrid. 
  
Regards,
Sabaridass R
 
 


Juraj Tomana
Replied On December 15, 2016 02:43 AM

Hi.

But how does it work? 

I was trying this:

    private void OnQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
    {
      e.Style.Text = "xxx";
      e.Style.CellValue = "xxx";

      e.Style.CellItemTemplate = (DataTemplate) AssociatedObject.Resources["cellTemplate"];

      e.Style.ContextMenuItemSource = new string[]
      {
        "xx",
        "yy"
      };
    }

, but nothing happend.

Can you make some sample for me, please?

Thanks.
Regards,
Juraj

Sabaridass Ramamoorthy [Syncfusion]
Replied On December 16, 2016 04:30 AM

Hi Juraj, 
 
We have created a simple sample to achieve your requirement – “Apply cell template for custom summary values” and please find the samples from the following location. 
 
 
Please refer to the following code example. 
# 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; 
            } 
        } 
 
Regards, 
Sabaridass R. 


Juraj Tomana
Replied On December 16, 2016 08:00 AM

Hi.

Thanks, but I have 2 problems with this solution (see attached videos):

1) CellItemTemplate is not applied (Background and Foreground works fine)..

2) 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?

Thanks.
Regards,
Juraj



Attachment: 127796_video_638535a0.zip

Sabaridass Ramamoorthy [Syncfusion]
Replied On December 19, 2016 05:35 AM

Hi Juraj, 
 
Please find the details below. 
 
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. 
#MainWindow.Xaml 
<Window.Resources> 
        <DataTemplate x:Key="CustomSummaryTemplate" > 
            <Border     
            Name="Border" 
            Background="Green" 
            BorderBrush="#888" 
            BorderThickness="1" 
            CornerRadius="4"> 
                <TextBlock Text="{Binding CellBoundValue}"  Background="BlueViolet"  Foreground="Orange" /> 
            </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)) 
            { 
                e.Style.CellType = "DataBoundTemplate"; 
                e.Style.CellItemTemplate = this.Resources["CustomSummaryTemplate"] as DataTemplate;  
                e.Style.CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; 
                e.Handled = true; 
            } 
        } 
 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. 
 
Regards, 
Sabaridass R 
 


Juraj Tomana
Replied On December 19, 2016 08:14 AM

Hi.
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;

            }

 


without changing other style-attributes (alignment, padding, margin, background,...)?


Thanks.
Regards,
Juraj

Sabaridass Ramamoorthy [Syncfusion]
Replied On December 20, 2016 04:27 AM

Hi Juraj, 
 
Please find the details below. 
 
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.  
#MainWindow.Xaml.cs 
 
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)) 
            { 
                e.Style.CellValue = pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].FormattedText; 
                e.Style.Foreground = new SolidColorBrush(Colors.Yellow); 
                e.Style.HorizontalAlignment = HorizontalAlignment.Right; 
                e.Style.FlowDirection = pivotGrid1.FlowDirection; 
                e.Style.Borders.All = new Pen() { Brush = pivotGrid1.GridLineStroke, Thickness = 0.1 }; 
                if (pivotGrid1.PivotEngine[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType.ToString().Contains("TotalCell")) 
                { 
                    e.Style.Background = pivotGrid1.SummaryCellStyle.Background; 
                    e.Style.Font.FontFamily = pivotGrid1.SummaryCellStyle.FontFamily; 
                    e.Style.Font.FontSize = pivotGrid1.SummaryCellStyle.FontSize; 
                    e.Style.Font.FontWeight = pivotGrid1.SummaryCellStyle.FontWeight; 
                     
                } 
                else 
                { 
                    e.Style.Background = pivotGrid1.ValueCellStyle.Background; 
                    e.Style.Font.FontFamily = pivotGrid1.ValueCellStyle.FontFamily; 
                    e.Style.Font.FontSize = pivotGrid1.ValueCellStyle.FontSize; 
                    e.Style.Font.FontWeight = pivotGrid1.ValueCellStyle.FontWeight; 
                } 
                e.Handled = true; 
            } 
        } 
 
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? 
 
Regards, 
Sabaridass R. 


Juraj Tomana
Replied On December 22, 2016 07:01 AM

Hi.

Both problems are now solved. Thanks.

Regards,
Juraj

Sabaridass Ramamoorthy [Syncfusion]
Replied On December 23, 2016 12:35 AM

Hi Juraj, 
 
Thanks for the update. 
 
Regards, 
Sabaridass R. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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.

;