Alternating background colors can make grouped Finished Reports easier to read by visually separating one group from the next.
For Group Headers, Group Footers, and other non-detail bands, alternating colors can be applied using a Visual Basic BeforePrint script with a simple counter.
Note: This method is for group-level bands. Alternating colors in the Detail band are configured using Odd Style or Even Style instead.
Why Use Alternating Colors for Group Bands?
This can be useful when:
- Grouped sections need clearer visual separation
- A report relies heavily on Group Headers or Group Footers
- There is little or no Detail-band output
- Users need to scan grouped results more easily
Step 1: Select the XtraReport
Select XtraReport in the Report Explorer, or click outside the report design area to select the report itself.
Step 2: Change the Script Language to Visual Basic
In the Properties pane, locate Script Language and change it to:
Visual Basic
This article uses Visual Basic for the alternating-color script.
Important: The report’s Script Language must be set to Visual Basic for the script examples in this article to work as shown.
Step 3: Select the Target Band
Select the Group Header, Group Footer, or other non-detail band where you want the alternating colors applied.
In this example, the target band is:
GroupFooter1
Step 4: Open the Scripts Property
With the target band selected, expand Scripts in the Properties pane.
Step 5: Add a BeforePrint Script
Create a new BeforePrint script for the selected band.
Step 6: Add the Counter Variable
Above the Private Sub section, add:
Private Counter As Integer = 0This counter is used to switch between the two background colors.
Step 7: Add the Alternating Color Logic
Inside the BeforePrint script, add:
If Counter = 0 Then
GroupFooter1.BackColor = Color.White
Counter = 1
Else
GroupFooter1.BackColor = Color.Orange
Counter = 0
End IfThis alternates the selected band between White and Orange each time the band prints.
Note: Replace
GroupFooter1with the exact name of the band you are formatting.
Step 8: Verify the Script Is Attached to the Correct Band
Confirm that the BeforePrint script is attached to the intended Group Header or Group Footer.
Step 9: Confirm the Band Name in the Script
Make sure the band name referenced in the code matches the actual band name.
For example, if the target band is:
GroupHeader2
replace each instance of:
GroupFooter1
with:
GroupHeader2
Step 10: Validate and Preview
Validate the script and select Preview.
Confirm that:
- The intended group band alternates between the two colors
- The colors change from one group instance to the next
- The correct band is being formatted
- No script errors are displayed
Step 11: Save the Report
After confirming the alternating colors, save the Finished Report.
Comments
0 comments
Please sign in to leave a comment.