Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Cross-Tab

edited December 2001 in General
I'm new to RB.
I succeeded in generating a CrossTab in code. I add rows and values
depending on the user needs. Now I need something tricky. Depending on the
Grand Total of a row, I need to decide to show or not to show this row.
First, is it possible ? If so, how can I do this (wich event is fired at
the right moment and geves me access to the grand total before printing the
row)?

Thanks
--
Frederic Gelinas
www.si.qc.ca

Comments

  • edited December 2001
    The easiest way to hide a row, would be to create a calculated field on your
    dataset, and limit the dataset based on that calculation - the record would
    never get generated in the crosstab. This is the preferred approach.

    If this isn't feasible, then you'll need to get inside the crosstab
    renderer. Create a descendent cross tab renderer that is able to hide rows.
    You may be able to do this by modifying the generated crosstab matrix of
    values during generation. Set the values to some 'hide' flag value you want.
    Then when the renderer looks at the matrix values to generate the draw
    commands for the output, it can skip the matrix values that have this
    special 'hide' flag.

    Another option may be to just use the currently generated crosstab. Loop
    through all of the draw commands, looking for the grand totals that you want
    to hide. The fun part is going to be looping back through the draw commands,
    which are on the same row, and removing those. Now, all of the draw commands
    below the crosstab need to be shifted up one row height. You'll also have
    to modify the vertical gridlines draw commands. Use the Report.OnEndPage
    event to modify the draw commands on the page object, just before the page
    gets sent to the output device.



    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited December 2001
    Well. Not being really used to RB, I think I will try to limit my query
    before it is sent to the report. I won't be easy, but it will require less
    coding.

    Thanks a lot for you help.

    By the way, I really don't regret switching to RB. It is very easy to use
    and enough flexible to accomodate many situations. It worths the money!
    --
    Frederic Gelinas
    www.si.qc.ca

  • edited December 2001
    Here's how you can find a draw command on a page and remove it based on its
    text value. Here it searches for the CustNo = 1351 draw command.for a
    simple Orders dbDemos table crosstab.


    uses
    ppDrwCmd, ppDevice;

    procedure TForm1.ppReport1EndPage(Sender: TObject);
    var
    lPage: TppPage;
    liIndex: Integer;
    lDrawCommand: TppDrawCommand;
    liValue: Integer;
    lsText: String;
    liDrawCommandCount: Integer;
    begin

    lPage := ppReport1.Engine.Page;

    liDrawCommandCount := lPage.DrawCOmmandCount;
    liIndex := 0;

    while (liIndex < (liDrawCommandCount - 1)) do
    begin

    lDrawCommand := TppDrawCommand(lPage.DrawCommands[liIndex]);

    if lDrawCommand is TppDrawText then
    begin

    lsText := TppDrawText(lDrawCommand).Text;

    liValue := StrToIntDef(lsText, -1);

    if (liValue <> -1) then
    begin

    if (liValue = 1351) then
    begin
    lPage.RemoveDrawCommand(lDrawCommand);

    Dec(liDrawCommandCount);
    end;

    end;

    end;

    Inc(liIndex);

    end;

    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    ppReport1.Print;
    end;


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.