How to print rows in alternating colours

When printing a report it is often wanted to have every second row printed with a different colour to make it easier to read the output. To do so put the following code in the on_print action of a report field

Example 5.10. Printing alternate colours

if hk_thisreport.datasource().row_position() % 2 ==0:
   hk_this.set_backgroundcolour(hk_white)
else:
   hk_this.set_backgroundcolour(hk_grey)