Search code examples
vb.netvisual-studiowinformsreportingrdlc

Configure RDLC report's Height on runtime


I have been trying to change my report's paper size programmatically. The goal is to make it work wherein I can configure the RDLC report's paper/page size during runtime.

As I have seen on this Link. I can configure the paper size during runtime. I have followed it and managed to change the paper size on runtime, but when the report loads. It still uses the PageSize that is indicated on the report property.

Is there something here that I have missed out. I also tried using RefreshReport(). Am I misinterpreting that PageSize and PaperSize are the same? I don't see a PageSize property under the DefaultPageSettings so I assumed that they are the same.

The screenshot below shows the changed PaperSize during runtime. I have used a message box to see if it does change.

Message Box

But the report still uses the 1100 Height by 850 Width which is specified under the PageSize property.

Page Size


Solution

  • The Paper size which you set in Reports Properties page is the same as PageSize which you set in Properties window of the report. It determines the print page size of the report.

    To set the value at run-time:

    Dim pageSettings = New Printing.PageSettings()
    pageSettings.PaperSize = New Printing.PaperSize("Custom", 400, 400)
    Me.ReportViewer1.SetPageSettings(pageSettings)
    

    To see the impact:

    • Click on the Print Layout button at run-time:

    enter image description here

    Note

    • By changing InteractiveSize.Height you can change the page size in interactive mode (default view) of viewer. For example by setting the height to 0, all the items of the report will be shown in a single page. or by setting it to 2 inch, for example, each page will show that number of rows which fits in 2 inches. You can not change it at run-time.

    • By changing the page size, you will change the page size of the report in print layout. You can change it at run-time and design-time.

    • By changing report body width, you will change the amount of space the report body needs regardless of paper size. For example if you set the page width to something smaller than report body width, there will be page breaks when printing, to print right side of report body. You cannot change it at run-time.