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

Assigning Editors for In-place Editing

  • 4 minutes to read

This topic explains how to assign an editor to cells used only for in-place editing. For general information on in-place editors, see Cell Editors Overview.

Assigning Editors for In-place Editing

In-place editors can be assigned to all cells that correspond to a specific data field or to individual cells. By default, these editors will be used to represent cell values in display mode, and when an end-user starts editing, the same editor will be activated.

For those times when you may need to use a specific editor to represent data in display mode, but a different editor for in-place editing, do the following:

  1. Supply an editor that will be used in display mode (to a specific data field or to individual cells).
  2. After that, specify the editor that will be invoked solely for in-place editing using the PivotGridControl.CustomCellEditForEditing event.

    The PivotGridControl.CustomCellEditForEditing event fires when an end-user is about to start editing. Its parameters allow you to identify the currently processed cell. To provide an editor for editing, assign the corresponding RepositoryItem descendant to the event’s RepositoryItem parameter. Note that the repository item used should belong to the control’s DevExpress.XtraPivotGrid.PivotGridControl.RepositoryItems collection.

Example

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:

CustomCellEditForEditing_ex

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() {
            InitializeComponent();
        }

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

        private void Form1_Load(object sender, EventArgs e) {
            this.salesPersonTableAdapter.Fill(this.nwindDataSet.SalesPerson);

            // 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);
        }

    }
}
See Also