Sunday, May 13, 2012

Print alternating background colour in detail section of XtraReports for Lightswitch

Problem

The readability of a printed report with text and numbers can be improved by printing the details with and alternating colour, e.g. lines in white background alternate with lines in light grey background.

image

Solution

In a LightSwitch application with an XtraReports report, we can make the colours alternate by creating an EvenStyle and OddStyle in the Styles collection in the properties of the detail section. One of these styles will be given a different background colour from the other.

Prerequisites

The example is based on a view vEmployeeDepartment from the AdventureWorks database. The view has been added to the Datasource of the Lightswitch project. To create a report with grouping see my article about grouping with XtraReports 

How to set alternating background colours

  • In the XtraReports design, select the detail section. Click on the grey Details band.
  • In the properties window, expand the Styles Collection property
    image
  • The EvenStyle, OddStyle properties are displayed. Click on (none) near the EvenStyle.
    image
  • Click on the dropdown arrow, in the dropdown list, select (New)
    image
  • A new style is created with the name xrControlStyle1. Repeat the above step for OddStyle.
    image
  • A 2nd style is created , called xrControlStyle2.
    image
  • Now we have to set the background colour of these styles to a different colour. By default the background of both styles will be transparent. We will only modify the background of the OddStyle to WhiteSmoke. To modify click on (Collection) of the Styles collection, so that a button ‘…’ appears.
    image
  • Click on the button ‘…’. IN the Styles editor dialog window select ‘xrControlStyle2’.
    image
  • In the right-hand panel, click (Not set) near the BackColor property to open a dropdown with colours. Select the WhiteSmoke colour.
    image
  • Click Close.
  • Now the background will be printed in alternating white and WhiteSmoke colour as shown in the start of this article.

Remark

In XtraReports, you have to fit your labels together horizontally, so that there is no white space. Because the details background only shows where there are controls. It is not quite as one would expect. If your labels don’t fit together the alternate colour will not show up.
image

No comments: