| |
 |
How to: Override the Default Cell Editor for the In-Place Editing
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:

C#: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();
}
RepositoryItemTextEdit riTextEdit = new RepositoryItemTextEdit();
RepositoryItemProgressBar riProgressBar = new RepositoryItemProgressBar();
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[] { riTextEdit, riProgressBar });
}
void pivotGridControl1_CustomCellEdit(object sender, PivotCustomCellEditEventArgs e) {
if (e.DataField == fieldQuantityPercent & e.RowValueType == PivotGridValueType.Value)
e.RepositoryItem = riProgressBar;
}
void pivotGridControl1_CustomCellEditForEditing(object sender, PivotCustomCellEditEventArgs e) {
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);
}
}
}
|
VB: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
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)
fieldQuantity1.SummaryDisplayType = DevExpress.Data.PivotGrid.PivotSummaryDisplayType.PercentOfColumn
fieldQuantity1.CellFormat.FormatType = DevExpress.Utils.FormatType.Custom
fieldQuantity1.CellFormat.FormatString = "{0}%"
pivotGridControl1.RepositoryItems.AddRange(New RepositoryItem() {riProgressBar, riTextEdit})
End Sub
Private Sub pivotGridControl1_CustomCellEdit(ByVal sender As Object,
ByVal e As PivotCustomCellEditEventArgs) Handles pivotGridControl1.CustomCellEdit
If e.DataField Is fieldQuantity1 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
If e.DataField Is fieldQuantity1 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 fieldQuantity1 Then
e.Value = Math.Round(Convert.ToDecimal(e.Value) * 100, 2)
End If
End Sub
End Class
End Namespace
|
Is this topic helpful?
Additional Feedback
Close
|