Skip to main content
Tag

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

PivotGridField.CellTemplate Property

Gets or sets a template used to display cells that correspond to the current field. This is a dependency property.

Namespace: DevExpress.Xpf.PivotGrid

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

NuGet Package: DevExpress.Wpf.PivotGrid

#Declaration

public DataTemplate CellTemplate { get; set; }

#Property Value

Type Description
DataTemplate

A DataTemplate object used to display cells that correspond to the current field.

#Remarks

If the CellTemplate is not specified, the cells are displayed via the PivotGridControl.FieldCellTemplate template (or the PivotGridControl.FieldCellKpiTemplate if this field displays KPI graphics). The PivotGridField.ActualCellTemplate property allows you to obtain which template is currently used.

You can implement custom logic to choose the required template using the PivotGridField.CellTemplateSelector property.

#Example

The PivotGrid control does not support the data editing functionality out of the box because it displays aggregated data. This example demonstrates how to implement a custom CellTemplate with the in-place editing functionality.

This example implements the base editing features. It does not allow going to the next cell by pressing the tab or arrow keys.

The PivotGridEditHelper class implements the in-place cell editor. When editing is finished, the editor calls the pvotGridControl1_OnCellEdit method. This method retrieves the underlying data for the edited cell and adjusts them so that their sum equals the new value entered in the cell.

View Example: How to Edit a Cell with the Cell Editing Template

using System;
using System.Collections.ObjectModel;
using System.Windows;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.PivotGrid;

namespace HowToEditCell {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : ThemedWindow {

        public ObservableCollection<MyOrderRow> OrderSourceList { get; set; }

        public MainWindow() {
            InitializeComponent();
        }

        void Window_Loaded(object sender, RoutedEventArgs e) {
            OrderSourceList = DatabaseHelper.CreateData();
            pivotGridControl1.DataSource = OrderSourceList;
            pivotGridControl1.BestFit();
        }

        void pivotGridControl1_OnCellEdit(DependencyObject sender, PivotCellEditEventArgs args) {
            PivotGridControl pivotGrid = (PivotGridControl)sender;
            PivotGridField fieldExtendedPrice = pivotGrid.Fields["ExtendedPrice"];
            PivotDrillDownDataSource ds = args.CreateDrillDownDataSource();
            decimal difference = args.NewValue - args.OldValue;
            decimal factor = (difference == args.NewValue) ? (difference / ds.RowCount) : (difference / args.OldValue);
            for(int i = 0; i < ds.RowCount; i++) {
                decimal value = Convert.ToDecimal(ds[i][fieldExtendedPrice]);
                decimal newValue = (value == 0m) ? factor : value * (1m + factor);
                ds.SetValue(i, fieldExtendedPrice, newValue);
            }
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CellTemplate 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