RDLC 报表调用PrintDialog() 时出现 “对象的当前状态使该操作无效”

NET321 2009-08-03 09:01:31

/// <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) 位置
...全文
721 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
anly20011 2011-09-26
  • 打赏
  • 举报
回复
Me临时解决办法.

加入一个timer1控件

在reportviewer1的RenderingComplete事件
timer1.start()

在timer1的Tick事件
me.ReportViewer1.PrintDialog()

以上可以解决提示出错的问题.
感觉出错的原因是数据未加载完所致的.望有高手能切底解决这一个问题.

lsj_zrp 2009-09-01
  • 打赏
  • 举报
回复
这是因为SetReport();的时候会加载报表,而报表还没有加载完就调用了this.reportViewer1.PrintDialog();引起的
调用RefreshReport的时候,报表会加载数据并绘制(没有深入了解,怀疑这个地方不是在主进程里面进行的,所以就直接执行PrintDialog(),而不是等待数据加载完成后再执行PrintDialog(),从而导致错误)
woheni2008523 2009-09-01
  • 打赏
  • 举报
回复
帮顶!
wanggenhu0 2009-09-01
  • 打赏
  • 举报
回复
帮顶
NET321 2009-08-04
  • 打赏
  • 举报
回复
有人帮忙吗?
llsen 2009-08-03
  • 打赏
  • 举报
回复
rdlc不熟悉
你用得是c/s还是b/s
NET321 2009-08-03
  • 打赏
  • 举报
回复
谁能帮忙解决下 !
yanm7788 2009-08-03
  • 打赏
  • 举报
回复
oooo
NET321 2009-08-03
  • 打赏
  • 举报
回复
如果数据不清空怎么去更新报表里的数据啊!
「已注销」 2009-08-03
  • 打赏
  • 举报
回复
最好是不要把数据源清空了,这样的话虽然再次给它加载数据源还是容易出错。
lghndyz 2009-08-03
  • 打赏
  • 举报
回复
帮顶!!
NET321 2009-08-03
  • 打赏
  • 举报
回复
郁闷!
NET321 2009-08-03
  • 打赏
  • 举报
回复
在c/s 模式下

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧