How to get a fixed number of rows in master band of grouped repoprt?

hsmhsm
edited 8:02AM in FastReport 4.0
I have a simple grouped report where each group in the dataset can have between 1 and 8 rows of data.
However, I need to always have 8 rows shown in the master band for each group, even if some of them are empty.
How can I always have 8 rows in each group, some with data and some with justy empty boxes?

This is a similar problem to the many 'invoice' type questions on this forum.
I have tried adapting the test8.fr3 provided by gpi in reply to ' Simple Invoice, Need help with fixed height detail band' but that (and answers to other fixed rows problems) assume the master band shows the entire dataset.
As soon as I use a group band I get data from more than one group in the master band and the layout is wrong.

Attached is my report file, based on gpi's sample. (It also shows where I need to have a the group footer showing the average of one of the fields in the group, but averaged out of 10, not 8)

Comments

  • gordkgordk St.Catherines On. Canada.
    edited March 2014
    in the obp of the groupfooter write code to display an unattached child band containing empty memos
    use the line variable to find out how many lines you have and show the band using the engine.showband method
    the number of times required
  • hsmhsm
    edited 8:02AM
    Thanks gordk, that did it.
    For the benefit of others (or for me if I forget how to do this!)

    The final report is this...
    procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
    // Referring to the system variable <line> in the group footer returns how many rows of real data 
    // were printed in that group.
    //  We always want 8 rows shown, so print (8 - <line>) child bands containing empty boxes after 
    //  the group data finishes but before we show the groupfooter 
    var i : integer;                                   
    begin
     for i := 1 to  8 - <Line> do  
       engine.showband(child1);   // this band is unattached and has only empty boxes in it                                               
    end;
    


  • hsmhsm
    edited 8:02AM
    Ah, just noticed a new issue though. I had a memo in the group footer that prefomed a SUM() on one of the fields in the grouped master band.
    Now those groups with less than 8 rows - and hence those showing some child bands - no longer show the sum. No error, just nothing shown

  • hsmhsm
    edited 8:02AM
    Solved using a variable in the code part of the report to keep a running total, but if there is a better way I'd prefer to do it that way
    Code I used was
    var
       TotalPoints : integer;                                              
    
    procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
    var i : integer;                                   
    begin
      MemoPointsTotal.text :=   FormatFloat('#.0',TotalPoints / 10);    //show average out of 10
      for i := 1 to  8- <Line> do
           engine.showband(child1);  //print blank rows
    end;
    
    procedure MasterData1OnAfterPrint(Sender: TfrxComponent);
    begin
    TotalPoints := TotalPoints + <frxDBDataset1."EstimatedPoints">  //keep running total of points
    end;
    
    
    procedure GroupHeader1OnAfterPrint(Sender: TfrxComponent);
    begin
    TotalPoints := 0;    //initialise running total of points each group
    end;
    
  • gordkgordk St.Catherines On. Canada.
    edited 8:02AM
    Did your sumfunction in the memo refrence the band or just the datafield?
  • gordkgordk St.Catherines On. Canada.
    edited 8:02AM
    another method to use is make the report 2 pass on the first pass store the value in an array
    in the final pass do the childband and sub the array value.
    just like doing the total in group header demo only do it in the footer
  • hsmhsm
    edited March 2014
    gordk wrote: »
    Did your sumfunction in the memo refrence the band or just the datafield?

    The memo contained

    [SUM(<frxDBDataset1."EstimatedPoints">,MasterData1)]

    The only bands at the moment are a group header, grouping on another field in the dataset, MasterData1 and a group footer.
    The above memo was in the group footer.

    Using your code to give me the illusion of 8 master bands by using empty child bands to make up the difference, the sum function shows the correct value if there are 8 master data rows but shows nothing at all if any of the 8 'rows' are made up from child bands
  • gordkgordk St.Catherines On. Canada.
    edited 8:02AM
    try
    [SUM(<frxDBDataset1."EstimatedPoints">,MasterData1,1)]

    another method assuming you start a new page for each person
    would be to use the overlay band draw your lines vertical and horizontal on it.
    then you only need to force the footer down to where you want it by setting the engine.cury in the obp of the footer

  • hsmhsm
    edited 8:02AM
    gordk wrote: »
    try
    [SUM(<frxDBDataset1."EstimatedPoints">,MasterData1,1)]

    another method assuming you start a new page for each person
    would be to use the overlay band draw your lines vertical and horizontal on it.
    then you only need to force the footer down to where you want it by setting the engine.cury in the obp of the footer

    No, still the same result, blanks when there are child bands.
    It doesn't matter though, the method I an using by calculating it myself in the obp / oap works fine. I was just intrigued as to why the SUM() didn't work
    I can't use the overlay band as there will be many of these little 8 row tables on each page - maybe even two columns of then.
    Thanks for your help gordk, don't worry about it. I'll use the code that works.
    Regards
  • hsmhsm
    edited 8:02AM
    SOLUTION

    The solution was not to use the OnBeforePrint event to draw the child bands inside a loop but instead use the OnAfterCalcHeight event.

    That showed the blank rows in the group as it should do but also allowed the SUM() function in the group footer to operate correctly.

    (is this a bug in the obp event I wonder?)



  • gordkgordk St.Catherines On. Canada.
    edited 8:02AM
    no it is not a bug, when the bands are set to stretch we need to use the onafter calc height event

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.