Search code examples
c#crystal-reports

c# how i can hide crystal "SubReport" programmatically?


iam using viual studio 2015 and crystal report and i have tow subReport how can i hide section or sub report when the row count is 0 or table empty

i try this : 1-go to section expert 2-click in x-2 button 3-write this on formula

       if ({Alarms.ID1}>1) then true
        if (sum({Alarms.ID1})>0 then false else true
        if (isNull({Alarms.ID1}) then true

and try a lote but it dosn't work

but it dosnt work what is the probelm ?? what i shoud do ?


Solution

  • You should use the feature to allow to auto suppress when empty.

    1. Go in the main report
    2. Right click the subreport
    3. select "format object"
    4. Click the subreport tab
    5. Check "Suppress Blank Subreport"

    Once that is done just make sure all section in the sub report are actually properly suppressed when there is no data then the main report will detect it's empty and will not print it.

    To check for empty you can simply do a count over the column of your dataset like the following. In the suppress of each section in the subreport simply put the following. If there is no count (no record) the section will suppress.

    count({Alarms.ID1}) = 0
    

    or you could use the long way and write the following if you prefer this syntax

    if count({Alarms.ID1}) = 0 then true
    else false