"Green Bar" report with repeating group header

Posted by: sewers on 14 September 2017, 9:20 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 9:20 am EST

    [activereports_archive]I followed the instructions in the ActiveReports 7 User Guide, pages 366 - 367, on how to create a “Green Bar” report (one where background colors alternate each row). This worked great initially, but now that I’ve changed the RepeatStyle of the GroupHeader to “OnPage”, I am getting a repeat background color at the top of each page after the first. So, on page 2 and on the first two rows are the same color before beginning to alternate again. This behavior does not happen until the RepeatStyle of the header is changed to “OnPage”.







    I am using a section report in an asp.net webforms project, rendering the report in a WebViewer.







    UPDATE: I did some hacking around before posting this, and I found that the issue seems to be that the event is called regardless of whether it’s the header or the detail that is being rendered. Since the event code alternates the color of the detail section and then flips the color flag, the fact that this event is called when the header is rendering on each page causes the issue. It seems to me that this happens because the header is for some reason rendered AFTER the first data row.







    Looking further into it, you can see that this probably happens because the page is still rendering the last row of the preceding page before rendering the header on the new page. So, the order would be:







    - Render last-row overflow from first page onto second page as color #1 (even if it seems to be a full, new row on the new page)







    - Render second page header as color #2 (but color is ignored because it’s rendering the header, not the detail







    - Render next detail row on second page as color #1. Now you have two detail rows with the same background color.







    My fix was easy. Just capture the sender and find out whether it’s rendering a header or detail row, and only execute the color logic if it is a detail row. The code:











    private void groupHeader1_Format(object sender, EventArgs e)



    {



    GrapeCity.ActiveReports.SectionReportModel.Section section =



    sender as GrapeCity.ActiveReports.SectionReportModel.Section;







    if (section.Type == GrapeCity.ActiveReports.Document.Section.SectionType.Detail)



    {



    if (color)



    {



    this.detail.BackColor = System.Drawing.Color.LightGray;



    color = false;



    }



    else



    {



    this.detail.BackColor = System.Drawing.Color.Transparent;



    color = true;



    }



    }



    }







    I hope this helps someone in the future. Also, unless I am wrong about my details above, I recommend that the documentation be updated to include the above, altered code snippet.



    [/activereports_archive]

  • Posted 14 September 2017, 9:20 am EST

    [activereports_archive]Scott,



    Thank you for updating the thread and good to know that you were able to resolve the issue.



    Regards,

    Sankalp

    [/activereports_archive]

  • Posted 14 January 2022, 7:54 am EST

    I’m getting the same symptom as described above but it’s because I’m trying to start each section with a “green” bar so I reset the boolean in the section_format event. My color flipping logic is called in the detail_format event, the same as the sample code in the docs. The issue detailed above is due to the color flipping logic in the header_format event. Not sure how I would solve my problem. I guess I’ll have to settle to not reset the color with every new section.

  • Posted 17 January 2022, 3:35 pm EST

    Hi Steve,

    I was able to replicate this behavior. Based on my observation when the detail.KeepTogether is set to True the last detail section sometimes moves to the other page. And since the color flip logic is in the detail.Format event it is called once for the format event of the detail section brought to the new page (assumed to be colored) and then the groupHeader1.Format event is called resetting the flag and the detail section is printed and then the new detail section is formatted with the reset flag causing there to be two consecutive colored section in the starting of the page.

    To solve this issue please call the color changing logic in the detail.BeforePrint event instead of detail.Format event.

    Please refer to the sample I have shared along with.

    AlternateColorSectionReport.zip

  • Posted 17 January 2022, 5:05 pm EST

    That worked. Thanks!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels