Search code examples
visual-studiocrystal-reports

Alternating the background color of rows or text boxes


I have data coming from data base in crystal report by SAP with VS2010 SQLServer, displayed in text boxes since Crystal doesn't have data grids.

How can there I alternate the background colors of those text boxes?


Solution

  • Create a custom formula; call it 'Colorize':

    //Color every other row as light tan (alter RGB to suit tastes)
    Function (Numbervar row, Optional Numbervar Color := RGB(239,235,220))
    
    If Remainder(row,2)=0 Then
        Color
    Else
        crNoColor
    

    Add the following to the Detail section's Background Color conditional-formatting formula:

    Colorize(RecordNumber)
    
    //or over-ride color
    Colorize(RecordNumber, crSilver)
    

    You can also use it with group header section by passing the GroupNumber keyword:

    Colorize(GroupNumber)
    

    If you are doing anything fancy w/ grouping, you may want to use a running-total formula:

    //{@G1}
    WhilePrintingRecords;
    Numbervar i;
    i:=1+1;
    

    Add this formula to group-header section, then suppress it.

    Change the grouper-header's conditional formula to:

    WhilePrintingRecords;
    Numbervar i;
    Colorize(i);