首页 新闻 会员 周边

c# ReportViewer报表问题?

0
悬赏园豆:10 [已解决问题] 解决于 2013-10-11 11:00

问题描述。

我有个窗体(窗体aa),放了Microsoft.Reporting.WinForms.ReportViewer(名字为RvReportViewer)。

我在窗体(窗体bb)的一个按钮上点击,这是new出一个窗体aa,同时把数据源DataSet传递给窗体aa,然后绑定RvReportViewer上去。

第一次显示没有问题,但是我关闭aa窗体后,再点击按钮查看后正常“显示如图”

但是,关闭这个窗体后,再次点击进来就显示错误了,就只是显示一页了,只显示了显示了第二页,如图:

这个是啥错误啊,我打断点看了,数据源没有问题,两次的数据源都是一样的。自从第一次点击后,再次点击查看后都是这样的错误。

aa显示的窗体,代码参考如下:

public partial class frmReportsViewer : Form     {

public frmReportsViewer()   { InitializeComponent(); }        

public frmReportsViewer(DataSet ds, String reportName, String formName)         {            

InitializeComponent();  

SetReport(ds, reportName, formName);        

}

        public void SetReport(DataSet ds, String reportName, String formName)         {            

try            

{                

this.Text = formName + "预览";                

this.RvReportViewer.ProcessingMode = ProcessingMode.Local;

this.RvReportViewer.LocalReport.ReportPath = reportName;

this.RvReportViewer.LocalReport.DataSources.Clear();                

for (int i = 0; i < ds.Tables.Count; i++)                

{                    

RvReportViewer.LocalReport.DataSources.Add(new ReportDataSource(ds.Tables[i].TableName, ds.Tables[i]));                

}                          

this.RvReportViewer.ZoomMode = ZoomMode.Percent;  

this.RvReportViewer.ZoomPercent = 100;   

this.RvReportViewer.RefreshReport();            

}            

catch (Exception ex)  {   

MessageBox.Show(ex.Message.ToString());            

}    

}

   private void frmReportsViewer_Load(object sender, EventArgs e)        

{            

this.RvReportViewer.RefreshReport();

this.RvReportViewer.SetDisplayMode(DisplayMode.PrintLayout);  

this.RvReportViewer.ZoomMode = ZoomMode.Percent;

this.RvReportViewer.ZoomPercent = 100;        

}    

}

夜星冷的主页 夜星冷 | 初学一级 | 园豆:71
提问于:2013-10-10 17:04
< >
分享
最佳答案
0

我自己用到的办法是

在this.RvReportViewer.RefreshReport();           之前加上 this.RvReportViewer.ZoomPercent = 100;

睡眠后在刷新显示就没问题了

夜星冷 | 初学一级 |园豆:71 | 2013-10-11 10:59

代码复制错了:改:

 System.Threading.Thread.Sleep(100);

夜星冷 | 园豆:71 (初学一级) | 2013-10-11 11:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册