运行期设置cxDBPivotGrid字段的统计类型

       cxDBPivotGrid这么强大的控件,如果不能在运行期指定字段的统计类型,实在是太遗憾了(希望是我没有找到此功能),所以就动手添加。

1、  首先寻找切入口。一种方法是改控件本身,第二种方法是在控件外部实现对控件增加功能。在看源码寻找切入点的过程中,发现还是直接改控件本身较简单。

在单元中cxPivotGridAdvancedCustomization中有双击事件ListBoxDblClick(Sender:TObject),实现了行区和列区字段的排序功能,却没有修改数据区字段统计类型的功能。所以只需要修改此方法,增加对数据区字段的判断(红色字体为增加的代码),将实现的代码放在另外一个单元中,尽量减少对控件自身单元的修改(方便控件升级时该功能的迁移):

procedureTcxPivotGridAdvancedCustomizationForm.ListBoxDblClick(Sender: TObject);

var

  AListBox: TcxFieldListListBox;

begin

  if CanChangeFieldFilter then

  begin

    AListBox := TcxFieldListListBox(Sender);

    UpdateHitTest;

    if(AListBox.SelectedField <> nil) and (AListBox.SelectedField.Area =faData) then

     EditPivotField(AListBox.SelectedField)

    else

    if (AListBox.SelectedField <> nil)and not PivotGrid.HitTest.HitAtFilter then

     ChangeFieldSorting(AListBox.SelectedField);

  end;

end;

2、  实现方法EditPivotField

functionEditPivotField(PivotField: TcxPivotGridField): Boolean;

var

  f: TfEditPivotField;

begin

  Result := False;

  f := TfEditPivotField.Create(Application);

  f.lFieldName.Caption := '统计字段: ' +PivotField.Caption;

  f.lFieldName.Font.Style := f.Font.Style +[fsBold];

  f.ListBox1.ItemIndex :=Ord(PivotField.SummaryType);

  f.edtDisplay.Text :=PivotField.DisplayFormat;

  if f.ShowModal = mrOk then

  begin

    PivotField.SummaryType :=TcxPivotGridSummaryType(f.ListBox1.ItemIndex);

    PivotField.DisplayFormat :=f.edtDisplay.Text;

    Result := True;

  end; 

  f.Free;

end;

3、  效果图

运行期双击数据区的‘数量’或者‘金额实收’,即可弹出统计类型设置窗口。

                                                                                                        

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值