我有一个应用程序,我必须在RDLC
不显示 printDialog 并使用应用程序中定义的默认指定打印机的情况下打印报告。下面是我的测试实现代码。
Microsoft.Reporting.WinForms.ReportViewer reportViewerSales = new Microsoft.Reporting.WinForms.ReportViewer();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSourceSales = new Microsoft.Reporting.WinForms.ReportDataSource();
reportViewerSales.Reset();
reportViewerSales.LocalReport.ReportPath = @"Sales.rdlc";
reportDataSourceSales.Name = "SalesTableDataSet";
int i = 1;
foreach (Product item in ProductSalesList)
{
dataset.CurrentSales.AddCurrentSalesRow(i, item.Name, item.Quantity.ToString(), item.Price.ToString(), item.Price.ToString());
i++;
}
reportDataSourceSales.Value = dataset.CurrentSales;
reportViewerSales.LocalReport.DataSources.Add(reportDataSourceSales);
dataset.EndInit();
reportViewerSales.RefreshReport();
reportViewerSales.RenderingComplete += new RenderingCompleteEventHandler(PrintSales);
这是我的渲染完成方法
public void PrintSales(object sender, RenderingCompleteEventArgs e)
{
try
{
reportViewerSales.PrintDialog();
reportViewerSales.Clear();
reportViewerSales.LocalReport.ReleaseSandboxAppDomain();
}
catch (Exception ex)
{
}
}