Search code examples
crystal-reportsreportreportingcrystal-reports-xi

Auto adjust column size, position if some columns null


I have a simple report with about 20 columns. Some of these columns might be empty. Here's what I am trying to do:

  1. Check if a column is empty.
  2. If it is empty, then readjust the position and size of rest of the columns to fill up the gap.
  3. Repeat steps 1-2 for every column.

I have some ideas of where to start with but not sure how to move forward. I can check if a column is empty by :

If DistinctCount({@SomeField}) > 0

I also know that the width and position can be changed by the formatting formulas. But how do I put this together? That is, what logic would run to check and expand the columns and where do I put this logic? Should I be using global variables?

Any suggestion would be helpful.

Thanks

Note: I am using Crystal Report XI


Solution

  • Try this approach:

    WhileReadingRecords;
    Global booleanVar col1Empty := True;
    Global booleanVar col2Empty := True;
    ...
    if not IsNull({dbtable.col1}) then
      col1Empty := False;
    if not IsNull({dbtable.col2}) then
      col2Empty := False;
    

    Then use this global variables in suppres formulas.

    Then count how many are not empty can calculate the average column width.