Here's some new code that i felt was missing, it adds 3 new footer formula types:
[list]fkCount, the number of values in a column
fkDistinct, the number of unique values in a column
fkCustom, a user defineable formula (event).[list]
1) In Columns.pas extend TFormulaKind:
CODE
TFormulaKind = (fkNone, fkAverage, fkMaximum, fkMinimum, fkSum, fkCount, fkDistinct, fkCustom);
2) In CustomGridViewContol.pas add:
CODE
TColumnFooterValueEvent = procedure (Sender: TObject; ACol: Integer; var Value: Double) of object;
3) In TCustomGridViewControl add
CODE
FOnColumnFooterValue: TColumnFooterValueEvent;
and
CODE
property OnColumnFooterValue: TColumnFooterValueEvent read FOnColumnFooterValue write FOnColumnFooterValue;
4) In TCustomGridView add:
CODE
property OnColumnFooterValue;
5) In TGridView.CalculateFooter's CalculateColum add
CODE
var
s : WideString;
sl : TStringList;
s : WideString;
sl : TStringList;
and inside the case statement:
CODE
fkCount: FormulaSum:=RowCount;
fkDistinct: begin
sl:=TStringList.Create;
for i:=0 to RowCount-1 do
begin
s:=Cells[Index,i];
if sl.IndexOf(s)=-1 then
sl.Add(s);
end;
FormulaSum:=sl.Count;
sl.Free;
end;
fkCustom : if Assigned(OnColumnFooterValue) then OnColumFooterValue(Self,Index,FormulaSum);//veg
fkDistinct: begin
sl:=TStringList.Create;
for i:=0 to RowCount-1 do
begin
s:=Cells[Index,i];
if sl.IndexOf(s)=-1 then
sl.Add(s);
end;
FormulaSum:=sl.Count;
sl.Free;
end;
fkCustom : if Assigned(OnColumnFooterValue) then OnColumFooterValue(Self,Index,FormulaSum);//veg
Thats all. When using it, don't forget to call TGridViews.CalculateColum to update the footer.
Btw support for strings as footer values for tkCustom could even make it more versatile.











