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]