How To Set Textbox1 Value Into Formula Field Of Cystal Reports

我的未来我决定 提交于 2019-12-24 01:48:20

问题


I want to set textbox1 value into formula field of crystal reports and Utilise the same value into crystal reports.

Suppose my Textbox1 value is “12000” and I want to set it to formula field and utilize the same into crystal reports. Is it possible?. And yes then How?.

Note: textbox1 located on top of CrystalReportviewer1.

Solution

It is very simple just create the instance of the reports class and set the textBox value in your crystalreportviewer source as under:

PLCrystReport plc = new PLCrystReport();
plc.DataDefinition.FormulaFields["ttt"].Text = "" + textBox1.Text + ""; 

For above first you have to create the formula field in your crystal reports and set the above code then after copy your formula field to your crystal reports. It will shows the specified value of textbox into formula field.

Note ["ttt"] is the formula field name. which provided into crystal reports.


回答1:


Dim RptForm As CrystalDecisions.CrystalReports.Engine.ReportDocument

Dim T As CrystalDecisions.CrystalReports.Engine.TextObject

RptForm = New MyCrystalReport()

T = RptForm.ReportDefinition.Sections(0).ReportObjects("TXTCNAME")

T.Text = DTPTDate.Value

Here TXTCNAME is the name of textbox present in Sections(0) of Crystal Report

MyCrystalReport is the crystal Report you want to use.




回答2:


First create an instance of your report class, then access the member variable and use that variable in your main interface.

Suppose I have a report class Called ReportView(), there I declared a member variable like

public CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocument;

Now in your report showing interface, create an instance of ReportView and follow:

ReportView rptView = new ReportView();
rptView.rptDocument.DataDefinition.FormulaFields["formulaName"].Text = "'" + txt.Text + "'";

Here, txt is a textbox that contain a value and formulaName is a formula created in the report design.




回答3:


when the Crystal report formula field is a DateTime , then the following code will helps you:

CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new ReportDocument();
rd.Load("AgedItems_3.rpt");
try
{
string datetext = RunDate.ToString("dd/MM/yyyy HH:mm");
rd.DataDefinition.FormulaFields["ProcessDate"].Text = "#"+datetext+"#";
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}


crystalReportViewer2.ReportSource = rd;



回答4:


Just add '' at between the text value ex: reportDoc.DataDefinition.FormulaFields("NameOfFormula").Text = "'Value'" . this must work fine.



来源:https://stackoverflow.com/questions/10926803/how-to-set-textbox1-value-into-formula-field-of-cystal-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!