cxGridDBTableView用代码创建页脚合计

本文探讨了在继承窗体中使用代码而非设计器创建页脚合计的方法,解决了频繁调整和列对应错误的问题。通过自定义函数和流程,提供了更高效、灵活的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建页脚合计在提供的设计器中可以很好的完成,但在开发时感觉效率不高,最重要的一个问题是如果窗口是继承的,会出现以下两个问题:

1、在子类的窗体中,设计器无法调整页脚合计--发生频繁较高;

2、在子类窗体中,通过设计器设计的页脚合计常会发生对应的列错误。

被以上两个问题折腾过的人应该都有自己的解决办法吧,我主要是通过用代码来创建:

procedure CreateFooterSummary(AcxGridView: TcxGridDBTableView; FieldNames: string;
  SumKind:TcxSummaryKind; AFormat:string);
  function SummaryExisted(AFieldName: string): Boolean; //是否已存在
  var
    i: Integer;
    aItem: TcxGridDBTableSummaryItem;
    aColumnField:string;
  begin
    Result := False;
    with AcxGridView.DataController.Summary do
      for i := 0 to FooterSummaryItems.Count - 1 do
      begin
        AItem := TcxGridDBTableSummaryItem(FooterSummaryItems[i]);
        if aItem.Column<>nil then
          aColumnField := TcxGridDBColumn(AItem.Column).DataBinding.FieldName;
        if SameText(aItem.FieldName,AFieldName)or((aColumnField<>'') and SameText(aColumnField,AFieldName)) then
        begin
          Result := True;
          Break;
        end;
      end;
  end;
var
  AList: TStringList;
  AFieldName: string;
  i: Integer;
  AItem: TcxGridDBTableSummaryItem;
begin
  AList := TStringList.Create;
  try
    AList.Delimiter := ';';
    AList.DelimitedText := FieldNames;
    for i := 0 to AList.Count - 1 do
    begin
      AFieldName := Trim(AList.Strings[i]);
      if AFieldName = '' then
        Continue;
      if SummaryExisted(AFieldName) = True then
        Continue;

      AItem := TcxGridDBTableSummaryItem(AcxGridView.DataController.Summary.FooterSummaryItems.Add);
      AItem.Column := AcxGridView.GetColumnByFieldName(AFieldName);
      AItem.Kind := SumKind;
      AItem.Format := AFormat;
    end;
  finally
    FreeAndNil(AList);
  end;
end;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值