mahesh
mahesh

Reputation: 1390

How To Set Textbox1 Value Into Formula Field Of Cystal Reports

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.

Upvotes: 3

Views: 14442

Answers (4)

Fremin Abreu
Fremin Abreu

Reputation: 127

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

Upvotes: 1

SUHAIL AG
SUHAIL AG

Reputation: 195

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;

Upvotes: 1

Mohammad Ashraf Ali
Mohammad Ashraf Ali

Reputation: 1

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.

Upvotes: 0

AurA
AurA

Reputation: 12373

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.

Upvotes: 2

Related Questions