Trouble Viewing Images? Right-click on any image and select "Open in new tab" to view a larger version. You can also zoom in using Ctrl + Mouse Wheel for easier readability.
Article Goal
Guide users through setting up alternating background colors for non-detail bands (such as Group Headers and Group Footers) in Finished Reports using scripts.
What / Why – Alternating Colors for Group Bands
What: Apply alternating background colors to Group Headers, Group Footers, or other non-detail bands using a script-based approach.
Why: Alternating colors improve readability and visual separation when reports rely on grouped sections instead of the Detail Band. Group bands require a different method than detail-level alternating styles.
Configuration Note
| Item | Details |
|---|---|
| Applicable bands | Group Headers, Group Footers, and other non-detail bands |
| Method used | Script-based logic using a counter |
| Detail Band usage | This method does not apply to the Detail Band |
| Script language | Must be set to Visual Basic |
For alternating colors in the Detail Band, refer to the dedicated detail-level alternating colors article.
Use Case
| Scenario | Description |
|---|---|
| Grouped layouts | Visually separate grouped sections such as employees, customers, or categories |
| No detail band | Use alternating colors when reports rely solely on group headers or footers |
| Improved readability | Make grouped sections easier to distinguish during review |
Steps to Set Up Alternating Colors for Group Bands
Step 1: Select the XtraReport
Select the XtraReport by using the Report Explorer or by clicking outside the report design area (outlined by the orange box).
Step 2: Change the Script Language
In the Properties pane, set the Script Language to Visual Basic.
Step 3: Select the Target Band
Select the band where you want alternating colors applied.
(This example uses GroupFooter1.)
Step 4: Open the Scripts Property
In the Properties pane, expand the Scripts dropdown.
Step 5: Add a BeforePrint Script
Add a new BeforePrint script for the selected band.
Step 6: Add a Counter Variable
Above the Private Sub section, add the following variable:
Private Counter As Integer = 0
This counter is used to toggle between background colors.
Step 7: Add the Alternating Color Logic
Paste the following code inside the BeforePrint script:
If Counter = 0 Then
GroupFooter1.BackColor = Color.White
Counter = 1
Else
GroupFooter1.BackColor = Color.Orange
Counter = 0
End If
Step 8: Verify the Script Is on the Correct Band
Confirm that the BeforePrint script is attached to the intended band.
(This example uses GroupFooter1.)
Step 9: Confirm Correct Band References in Code
Ensure the band referenced in the code matches the band you selected.
For example:
If using GroupHeader2, replace all
GroupFooter1references withGroupHeader2.
Step 10: Validate and Preview
Validate the script and preview the report to confirm the alternating colors are applied correctly.
Article Summary
This article explains how to apply alternating background colors to group-level bands in Finished Reports using a Visual Basic script. Since non-detail bands do not support style-based alternating colors, a counter-driven BeforePrint script is used to toggle background colors for each group instance. This approach improves readability and provides clear visual separation when reports rely on Group Headers or Footers instead of the Detail Band.
Comments
0 comments
Article is closed for comments.