Wait till winform loads before performing next action?
Winform application contains one form with a reportViewer control. When the form is initialized the report is generated but when I try to programmatically run a PrintDialog on the reportviewer I get a 'Operations is not valid due to the cu开发者_Python百科rrent state of the object' error message.
When I comment out the PrintDialog line the report form shows fine. I think the problem is a lag as it generates the form/report. Is there a way to wait until the form loads before launching the PrintDialog?
Code excerpt:
this.reportViewer1.RefreshReport(); this.reportViewer1.PrintDialog();
UPDATE
Solution is (as suggested):
private void form_load(...)
{
createReport;
this.reportViewer1.RefreshReport();
}
private void reportViewer1_RenderingComplete(...)
{
this.reportViewer1.PrintDialog();
}
This article suggestions you can't/shouldn't call PrintDialog until the RenderingComplete event fires:
http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportviewer.renderingcomplete(v=vs.80).aspx
http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/a8993f3e-7787-4e0a-b32f-fcfbf8df8001/
精彩评论