Jump to content


Photo

New Footer Formula's


  • Please log in to reply
No replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 18 March 2005 - 10:44 PM

Hi,

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;

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


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.
G.W. van der Vegt




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users