namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
reportViewer1.PrintDialog();
}
}
}
上述語法會跳出下面這個錯誤了解 PrintDialog() 之後,才發現原來是 RefreshReport() 時,ReportViewer 還在 Render 報表,此時 Code 會繼續往下執行,因為還在 Render 又遇上 PrintDialog() 就拋出錯誤
PrintDialog() 應該要放在 ReportViewer RenderingComplete Event 內最適合
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
private void reportViewer1_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e)
{
reportViewer1.PrintDialog();
}
}
}
沒有留言:
張貼留言