替换单元格的默认编辑器,操作步骤如下:
- 创建新的编辑器。如进度条:RepositoryItemProgressBar riProgressBar = new RepositoryItemProgressBar()
- 将新创建的新编辑器添加到 Pivot Grid 中。pivotGridControl1.RepositoryItems.AddRange(new RepositoryItem[] { riProgressBar })
- 在事件 CustomCellEdit 中指定单元格的编辑器。e.RepositoryItem = riProgressBar
- 示例代码:
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);
}