//Get the collection of parameters from the report crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields;
//Access the specified parameter from the collection crParameterFieldDefinition = crParameterFieldDefinitions["Country"]; //Get the current values from the parameter field. At this point //there are zero values set. crParameterValues = crParameterFieldDefinition.CurrentValues; //Set the current values for the parameter field crParameterDiscreteValue = new ParameterDiscreteValue(); crParameterDiscreteValue.Value = "Canada"; //1st current value //Add the first current value for the parameter field crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); //Set the viewer to the report object to be previewed. crystalReportViewer1.ReportSource = crReportDocument;
ReportDocument m_rptDoc = new ReportDocument();
m_rptDoc.Load(@"D:\ADJXC\LbReport\" + m_strRptFile+".rpt");
m_rptDoc.SetDataSource(m_dsParm);//m_dsParm是DataSet,里面包含两个表,是传递进来的参数;
crystalReportViewer1.ReportSource = m_rptDoc;
//以下自定义方法为水晶报表参数赋值
Hashtable ht = new Hashtable();
ht.Add("FontSize", 9); //为字体参数赋值
BuildReportViewerParameters(crystalReportViewer1, ht);// 当用户改变报表字体及页面设置时,需要刷新水晶报表
// 所以在工具栏的“刷新”按钮写下代码:
crystalReportViewer1.RefreshReport();// 刷新报表// 当执行这行代码时就出现“输入参数值”对话框,即使重新给报表参数赋值也一样。
// 很苦脑,搞了很久都不知要怎么才可以不出现“输入参数值”对话框?期待继续帮忙解决。
当然不能改写RefreshReport()方法。
要刷新水晶报表只有重新加载!这也太邪门了。
好象VB有个属性设置为false就可以防止弹出“输入参数值”对话框,但C#没有发现这样的属性。
参考:
http://blog.csdn.net/lifuyun/archive/2008/05/08/2416435.aspx
现在问题是更改了页面设置,再执行crystalReportViewer1.RefreshReport();// 刷新报表
会弹出“输入参数值”对话框。即使重新传递参数也一样。
像这样:
fs.SetParameterValue("total", 480);
fs.SetParameterValue("Leaftotal", 480);
this.crystalReportViewer1.ReportSource = fs;写成this.crystalReportViewer1.ReportSource = fs;
fs.SetParameterValue("total", 480);
fs.SetParameterValue("Leaftotal", 480);
估计就没事了
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues;
ParameterDiscreteValue crParameterDiscreteValue;crReportDocument = new CRParams();
//Get the collection of parameters from the report
crParameterFieldDefinitions = crReportDocument.DataDefinition.ParameterFields;
//Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions["Country"]; //Get the current values from the parameter field. At this point
//there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues; //Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = "Canada"; //1st current value //Add the first current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue); crParameterFieldDefinition.ApplyCurrentValues(crParameterValues); //Set the viewer to the report object to be previewed.
crystalReportViewer1.ReportSource = crReportDocument;
但只要一执行crystalReportViewer1.RefreshReport();// 刷新报表
会弹出“输入参数值”对话框。即使重新传递参数也一样。
我们希望是执行crystalReportViewer1.RefreshReport();// 刷新报表
不弹出“输入参数值”对话框。我看没有一个人能解决了!
逐步调试出来结果是一样的,但如果直接运行还是一样跳出来
用了Application.DoEvents();也不行
看LZ有没有好的办法学习下
当然不要重写RefreshReport()方法。
用textObject来实现啊。这样就不会弹出了
crystalReportViewer1.RefreshReport();把ReportSource重新赋一次值即可
crystalReportViewer1.ReportSource = rptDateExpired1;