Skip to main content

How to: Specify the Default Cell Editor

  • 3 minutes to read

The following code shows how to handle the PivotGridControl.CustomCellEditForEditing event to override the cell editor used for the in-place editing.

In the example, the RepositoryItemProgressBar in-place editor is created to represent values of the “Quantity %” field. In the edit mode, this repository item is changed to RepositoryItemTextEdit:


View Example

using System;
using System.Windows.Forms;
using DevExpress.Data.PivotGrid;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraPivotGrid;

namespace PivotGridControl_CustomCellEdit {
    public partial class Form1 : Form {
        public Form1() {

        // Creates new repository items.
        RepositoryItemTextEdit riTextEdit = new RepositoryItemTextEdit();
        RepositoryItemProgressBar riProgressBar = new RepositoryItemProgressBar();

        private void Form1_Load(object sender, EventArgs e) {

            // Specifies the type of data field and format settings.
            fieldQuantityPercent.SummaryDisplayType = PivotSummaryDisplayType.PercentOfColumn;
            fieldQuantityPercent.CellFormat.FormatType = DevExpress.Utils.FormatType.Custom;
            fieldQuantityPercent.CellFormat.FormatString = "{0}%";

            // Initializes cell editors for this Pivot Grid control.
            pivotGridControl1.RepositoryItems.AddRange(new RepositoryItem[] { riTextEdit, riProgressBar });

        void pivotGridControl1_CustomCellEdit(object sender, PivotCustomCellEditEventArgs e) {
            // Specifies a cell editor which is used in both display and edit modes.
            if (e.DataField == fieldQuantityPercent & e.RowValueType == PivotGridValueType.Value)
                    e.RepositoryItem = riProgressBar;            

        void pivotGridControl1_CustomCellEditForEditing(object sender, PivotCustomCellEditEventArgs e) {
            // Overrides the cell editor for the edit mode.
            if (e.DataField == fieldQuantityPercent & e.RowValueType == PivotGridValueType.Value) 
                    e.RepositoryItem = riTextEdit;            

        private void pivotGridControl1_CustomCellValue(object sender, PivotCellValueEventArgs e) {
            if (e.DataField == fieldQuantityPercent)
                e.Value = Math.Round(Convert.ToDecimal(e.Value) * 100, 2);