Click here to Skip to main content
15,888,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone

I have a report viewer that programmatically display a rdlc report when user click a button
in button event i do the following:

C#
System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
pg.Landscape = true;
pg.Margins.Top = 2;
pg.Margins.Bottom = 2;
pg.Margins.Left = 40;
pg.Margins.Right = 2;
system.Drawing.Printing.PaperSize size = new PaperSize();
size.RawKind = (int)PaperKind.A4Extra;
pg.PaperSize = size;
reportViewer1.SetPageSettings(pg);

DataTable dt = ReceiptsManager.GetAvowelsReportDT(<Parameters>);

if (dt != null && dt.Rows.Count > 0)
{
  reportViewer1.LocalReport.ReportPath = <RDLC Report Path>

  ReportDataSource RDS = new ReportDataSource();
  RDS.Name = <RDLC Report Dataset Name>;
  RDS.Value = dt;
  reportViewer1.LocalReport.DataSources.Clear();
  reportViewer1.LocalReport.DataSources.Add(RDS);

  this.reportViewer1.RefreshReport();
}


the report displayed well but when i click on Printpreview button the viewer displayed a small black box without any contents and when i press right click and choose a pagesetup i see my predefined settings and when i press OK the report displayed

So i want to solve this problem and when user click Printpreview the report displayed with predefined settings

Thanks in advance
Posted
Updated 24-Dec-18 2:22am
v2
Comments
mgoad99 3-Jul-13 13:47pm    
I have not had the same exact problem you describe, but i do know that users have to install an active x control to print from the report viewer (same as if running the report directly in the report manager). Typically, the first time a user tries to print they will get a message asking them to install the control. After they install it, they do not get that message anymore. Maybe there is an issue with the control that is giving your users a small black box instead of the message to install?
AhmedYehiaK 3-Jul-13 21:37pm    
as i mention before after we see the small black box i press right click and choose PageSetup then i see all the settings which i programmatically set then press OK

then the small black box disappeared and the report displayed well

So i can see and print the report as well but the whole problem in what i mention

1 solution

hi i had the same problem for long long time and after all i figured it out.

paper size has some values like height and width.
when you make a new object of PaperSize, these values are set to zero and when you set your paper to be A4, these values are zero again. so your paper size is not defined and as soon as you open pagesetup and click OK, the PaperSize is set to its true values.

so you have to set them manually. i used the pages default PaperSize and modified it instead of making a new object and my program worked correctly.

so just replace your code :
system.Drawing.Printing.PaperSize size = new PaperSize();

and put this:
system.Drawing.Printing.PaperSize size = pg.PaperSize;


in my case this solve the problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900