this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
this.reportViewer1.PrintDialog();
未处理 System.InvalidOperationException
Message="对象的当前状态使该操作无效。"
Source="Microsoft.ReportViewer.WinForms"
StackTrace:
在 Microsoft.Reporting.WinForms.ReportViewer.PrintDialog()
在 WinUI.Form1.button1_Click(Object sender, EventArgs e) 位置 E:\Demo\WinUI\WinUI\Form1.cs:行号 35
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WinUI.Program.Main() 位置 E:\Demo\WinUI\WinUI\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: 此问题我在几个月前就碰到过一直没解决
http://topic.csdn.net/u/20090803/09/920f4d85-afd6-4b65-aaac-c1c7c3388373.html/// <summary>
/// 设置报表
/// </summary>
private void SetReport()
{
if (reportModel != null)
{
if (ReportSource.Count > 0) ReportSource.Clear();
if (this.reportViewer1.LocalReport.DataSources.Count > 0) this.reportViewer1.LocalReport.DataSources.Clear();
ReportSource.Add(reportModel);
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("SMAccidentInfo_SimpleReport", ReportSource));
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
} } private void tsbPrint_Click(object sender, EventArgs e)
{
try
{
SetReport();
this.reportViewer1.PrintDialog();
}
catch (Exception ex)
{
Sys_Error.WriteError(this, ex);
}
}捕捉到 System.InvalidOperationException
Message="对象的当前状态使该操作无效。"
Source="Microsoft.ReportViewer.WinForms"
StackTrace:
在 Microsoft.Reporting.WinForms.ReportViewer.PrintDialog()
在 Report.FrmSimpleReport.tsbPrint_Click(Object sender, EventArgs e) 位置 希望高手帮忙看看!
放在 RenderingComplete 事件中试试!