Search code examples
vb.netwinformsdevexpressxtrareport

DevExpress Xtrareport Hide report header when detail section is empty


I have a report with Detail Band bound to datasource. in some cases, my report has multiple pages and the last page may contain Detail Band rows and other cases the last page has no Detail Band rows, so it will just show the page header with my report footer.

I want to hide the header when the last page has no detail rows.

I tried using PageHeader_BeforePrint Event, but I couldn't get any value to indicate whether the Detail section of this page is empty or not.

I used a row count label, but this counter in PageHeader_BeforePrint event always has the same value, although after printing finishes, the visible value of this counter is correct on every page.

so, the basic issue is: in PageHeader_BeforePrint How to determine whether the Detail Band section has rows or not?


Solution

  • Unfortunately there is no simple way to do that. The similar solution was described on the dx-support page

    you should manually count the rows and check it to cancel printing:

    private int rowCounter = 0;
    
            Detail.AfterPrint += (o, args) => { rowCounter++; };
            PageHeader.BeforePrint += (o, args) =>
            {
                if (rowCounter >= this.RowCount)
                    args.Cancel = true;
            };