Pivot Grid-09 自定义单元格的默认编辑器

替换单元格的默认编辑器,操作步骤如下:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值