This topic explains how to provide in-place editors for individual cells. For general information, see Cell Editors Overview.
To assign editors to individual cells, handle the PivotGridControl.CustomCellEdit event. This event occurs dynamically for each visible cell and specifies editors for individual cells depending on the cell's position and type. The editor that assigned using this event represents cell contents in display mode, and by default, is used for in-place editing. To provide a different editor to be used in edit mode, refer to Assigning Editors for In-place Editing for more details.
The PivotGridControl.CustomCellEdit event's parameters allow you to identify the cell being currently processed. To provide an editor for the currently processed cell, assign a specific repository item to the event's RepositoryItem parameter. You need to add the repository items to the Pivot Grid's repository (the collection).
Refer to the Repositories and Repository Items topic for details on repository technology.
The following code shows how to handle the PivotGridControl.CustomCellEdit event, to assign different in-place editors to different types of cells.
In the example, two in-place editors (repository items) are created to represent values of the "Quantity %" field. A ProgressBar editor is used to represent regular cell values, while a SpinEdit editor is used to represent total values for this field:

Form1.cs |
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();
}
RepositoryItemProgressBar riProgressBar = new RepositoryItemProgressBar();
RepositoryItemSpinEdit riSpinEdit = new RepositoryItemSpinEdit();
private void Form1_Load(object sender, EventArgs e) {
this.salesPersonTableAdapter.Fill(this.nwindDataSet.SalesPerson);
fieldQuantityPercent.SummaryDisplayType = PivotSummaryDisplayType.PercentOfColumn;
fieldQuantityPercent.CellFormat.FormatType = DevExpress.Utils.FormatType.Custom;
fieldQuantityPercent.CellFormat.FormatString = "{0}%";
pivotGridControl1.RepositoryItems.AddRange(new RepositoryItem[] { riProgressBar, riSpinEdit });
pivotGridControl1.CustomCellEdit += new
EventHandler<PivotCustomCellEditEventArgs>(pivotGridControl1_CustomCellEdit);
}
private void pivotGridControl1_CustomCellEdit(object sender, PivotCustomCellEditEventArgs e) {
if (e.DataField == fieldQuantityPercent) {
if (e.RowValueType == PivotGridValueType.Value)
e.RepositoryItem = riProgressBar;
if (e.RowValueType == PivotGridValueType.GrandTotal)
e.RepositoryItem = riSpinEdit;
}
}
private void pivotGridControl1_CustomCellValue(object sender, PivotCellValueEventArgs e) {
if (e.DataField == fieldQuantityPercent)
e.Value = Convert.ToDecimal(e.Value) * 100;
}
}
}
|
Program.cs |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace PivotGridControl_CustomCellEdit {
static class Program {
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
|
Program.vb |
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Windows.Forms
Namespace PivotGridControl_CustomCellEdit
Friend NotInheritable Class Program
Private Sub New()
End Sub
''' <summary>
''' The main entry point for the application.
''' </summary>
<STAThread> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1())
End Sub
End Class
End Namespace
|
Form1.vb |
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraPivotGrid
Namespace PivotGridControl_CustomCellEdit
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
' Creates new repository items.
Dim riProgressBar As New RepositoryItemProgressBar()
Dim riSpinEdit As New RepositoryItemSpinEdit()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
' Binds the pivot grid to data.
Me.salesPersonTableAdapter.Fill(Me.nwindDataSet.SalesPerson)
' Specifies the type of data field and format settings.
fieldQuantity1.SummaryDisplayType = DevExpress.Data.PivotGrid.PivotSummaryDisplayType.PercentOfColumn
fieldQuantity1.CellFormat.FormatType = DevExpress.Utils.FormatType.Custom
fieldQuantity1.CellFormat.FormatString = "{0}%"
' Initializes cell editors used to represent values of regular and total cells respectively.
pivotGridControl1.RepositoryItems.AddRange(New RepositoryItem() {riProgressBar, riSpinEdit})
End Sub
Private Sub pivotGridControl1_CustomCellEdit(ByVal sender As Object,
ByVal e As PivotCustomCellEditEventArgs) Handles pivotGridControl1.CustomCellEdit
' Specifies editors for cells depending on a cell type.
If e.DataField Is fieldQuantity1 Then
If e.RowValueType = PivotGridValueType.GrandTotal Then
e.RepositoryItem = riSpinEdit
End If
If e.RowValueType = PivotGridValueType.Value Then
e.RepositoryItem = riProgressBar
End If
End If
End Sub
Private Sub pivotGridControl1_CustomCellValue(ByVal sender As Object,
ByVal e As PivotCellValueEventArgs) Handles pivotGridControl1.CustomCellValue
If e.DataField Is fieldQuantity1 Then
e.Value = Convert.ToDecimal(e.Value) * 100
End If
End Sub
End Class
End Namespace
|