How To…Create Conditional Columns

Question

“How can I show multiple columns in certain cases, then revert back to a single column in other cases in the same report?”

Solution

Use x number of child subreports to act as each column, and a single full width subreport to act as the single column.  Then toggle the visibility of each subreport based on how many columns you would like to display for that particular detail.

Download: ConditionalColumnsUsingSubreports.zip

Sample Delphi code:

procedure TForm1.ppDetailBand1BeforePrint(Sender: TObject);
var
  lbVisible: Boolean;
begin

  //Show two columns every other detail band.
  lbVisible := ppDetailBand1.Count mod 2 = 0;

  ppSubreport1.Visible := lbVisible;
  ppSubreport2.Visible := lbVisible;

  ppSubreport3.Visible := not(lbVisible);

end;