Skip to main content
A newer version of this page is available. .

PivotGridControl.PrintFieldCellTemplateSelector Property

Gets or sets a template selector that chooses a print template for data cells based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v18.2.dll

Declaration

public DataTemplateSelector PrintFieldCellTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

A DataTemplateSelector descendant that chooses a template based on custom logic.

Remarks

A template that defines the presentation of data cells when the pivot grid is printed is specified by the PivotGridControl.PrintFieldCellTemplate property. If you have more than one template that can be used to render cells, you can implement custom logic to choose the required template. To do this, derive from the DataTemplateSelector class, implement the SelectTemplate method that returns a template which meets the required condition, and assign an instance of this class to the PrintFieldCellTemplateSelector property.

The PrintFieldCellTemplateSelector is used for those fields whose PivotGridField.PrintCellTemplateSelector property is not specified.

The PrintFieldCellTemplateSelector is in effect only if the PivotGridControl.PrintFieldCellTemplate property is set to null (Nothing in Visual Basic). Otherwise, the PivotGridControl.PrintFieldCellTemplate template is used.

If a field displays KPI data, the PivotGridControl.PrintFieldCellKpiTemplate and PivotGridControl.PrintFieldCellKpiTemplateSelector properties are used for this field.

To learn more, see Printing and Exporting.

Example

The following example demonstrates how to select print templates for the DXPivotGrid elements based on custom logic.In this example, the template used to print data cells is selected based on the share of the data cell value in the Column Grand Total value. If this share is bigger than 80% or less than 20%, the template selector applies a specific template that highlights the cell value and prints the warning sign near it.

using System;
using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.PivotGrid.Internal;
using DevExpress.Xpf.Printing;

namespace DXPivotGrid_SelectingPrintTemplate {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            picotGridControl1.DataSource =
                new nwindDataSetTableAdapters.SalesPersonTableAdapter().GetData();
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e) {
            PrintHelper.ShowPrintPreview(this, picotGridControl1);
        }
    }
    public class CellTemplateSelector : DataTemplateSelector {
        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            Window mainWindow = Application.Current.MainWindow;
            CellsAreaItem cell = (CellsAreaItem)item;

            // Calculates the share of a cell value in the Column Grand Total value.
            double share = Convert.ToDouble(cell.Value) / Convert.ToDouble(cell.ColumnTotalValue);

            // Applies the Normal template to the Column Grand Total cells.
            if (cell.ColumnValue == null)
                return mainWindow.FindResource("NormalCellTemplate") as DataTemplate;

            // If the share is too far from 50%, the Highlighted template is selected.
            // Otherwise, the Normal template is applied to the cell.
            if (share > 0.8 || share < 0.2)
                return mainWindow.FindResource("HighlightedCellTemplate") as DataTemplate;
            else
                return mainWindow.FindResource("NormalCellTemplate") as DataTemplate;
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PrintFieldCellTemplateSelector property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also