windowsforms-5896-controls-and-libraries-pivot-grid-data-shaping-editing-assigning-editors-for-in-place-editing.md
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.
Since all of our editor containers (Data Grid, Tree List, Pivot Grid, etc.) use similar approaches and APIs that allow you to replace default editors, you can also refer to the Data Grid documentation, the Cell Values, Editors, and Validation article.
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:
This example shows how to change the editor type when the editor is in “edit” mode.
The RepositoryItemProgressBar in-place editor (repository item) displays values of the “Quantity %” field as progress bars. In “edit” mode, the PivotGridControl.CustomCellEditForEditing event is raised to change this repository item to RepositoryItemTextEdit.
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);
// 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);
}
}
}
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 riTextEdit As New RepositoryItemTextEdit()
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
salesPersonTableAdapter.Fill(Me.nwindDataSet.SalesPerson)
' Initializes cell editors for this Pivot Grid control.
pivotGridControl1.RepositoryItems.AddRange(New RepositoryItem() {riProgressBar, riTextEdit})
End Sub
Private Sub pivotGridControl1_CustomCellEdit(ByVal sender As Object,
ByVal e As PivotCustomCellEditEventArgs) Handles pivotGridControl1.CustomCellEdit
' Specifies a cell editor which is used in both display and edit modes.
If e.DataField Is fieldQuantity And e.RowValueType = PivotGridValueType.Value Then
e.RepositoryItem = riProgressBar
End If
End Sub
Private Sub pivotGridControl1_CustomCellEditForEditing(sender As Object,
ByVal e As PivotCustomCellEditEventArgs) Handles pivotGridControl1.CustomCellEditForEditing
' Overrides the cell editor for the edit mode.
If e.DataField Is fieldQuantity And e.RowValueType = PivotGridValueType.Value Then
e.RepositoryItem = riTextEdit
End If
End Sub
Private Sub pivotGridControl1_CustomCellValue(ByVal sender As Object,
ByVal e As PivotCellValueEventArgs) Handles pivotGridControl1.CustomCellValue
If e.DataField Is fieldQuantity Then
e.Value = Math.Round(Convert.ToDecimal(e.Value) * 100, 2)
End If
End Sub
End Class
End Namespace
See Also