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