Search code examples
c#crystal-reports

Repeat header based on user choice


I have a report subreport with a group and the option "Repeat group header in each page" checked. But I need the user to be able to choose whether or not to show the group header on every page, or just the first time the group appears.

I set up a checkbox to let them choose, but how can I use this to tell the report not to repeat the header during run time?

Update

Beeing a Subreport I can not know which page will appear for the first time and I can not restart the numbering because it is necessary for the report.

I'm using CrystalReports in VS2005 and coding C# in VS2010, I'm working for a company and can't upgrade.

I'm trying to use a FormulaFieldDefinition in C# but I don't know how.


Solution

  • This could be done with a variable inside the sub-report.

    Create a formula-field with following content and place it somewhere in the detail-section:

    WhilePrintingRecords;
    booleanVar headerPrinted := True;
    

    In the suppresion-formula of the group-header place the following code:

    WhilePrintingRecords;
    booleanVar headerPrinted;
    

    The formula will set the variable to True as soon as the first detail is being printed.
    So the suppression formula evaluates to False only the first time the group header is being printed and to True on every subsequent time.

    So with a boolean parameter {?GroupHeader} to choose if the header should be printed or not the suppression-formula would look as follows:

    WhilePrintingRecords;
    booleanVar headerPrinted;
    
    If {?GroupHeader} And headerPrinted Then
        True
    Else
        False
    

    {?GroupHeader} = True would mean: Only show group-headers once.