logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Event Report.Custom Calc - pre-processing of the input data
  • Toilet paper printing

    March 30, 2020

    Gentlemen jokes aside! Today we are talking about toilet paper. This essential hygiene product was

    read more
  • The Event of ExportParameters in WebReport.Report

    October 5, 2020

    In FastReport 2020.1 we have added the ability to change export parameters. To do this,

    read more
  • PreviewControl.OnPrint and PreviewControl.OnExport Events

    October 1, 2020

    In FastReport 2019.4 added the ability to subscribe to PreviewControl.OnPrint and PreviewControl.OnExport events, which are

    read more
  • Connecting to Elasticsearch

    November 10, 2021

    Now FastReport .NET, Core, Mono, and OpenSource products allow connecting to Elasticsearch. Elasticsearch is a

    read more
  • MS Word format vs. Open Document Text. Which is better?

    October 19, 2020

    Speaking of text editors, we immediately present coryphaeus as Microsoft Word, which for many years

    read more

Event Report.Custom Calc - pre-processing of the input data

August 13, 2017

New CustomCalc event for the Report object is called when evaluating an expression in an object or when you receive data back from the data source. So we can use this event to intercept the data and spoofing. When this can be useful? For example, when you need to filter the values in the incoming data or to replace any row.

Let's look at an example. Сreate a simple WindowsForms application. Add the data source to the project, and the DataSet component. Also, place the component Report on the form.

In the drop-down menu of the Report component, select the item “Select Data Source”:

 

And choose our data source.

Now, select the item “Design Report” from the same menu. To demonstrate, I added a couple of fields from the Employee table:

 

For interest's see how the report looks now:

 

Save the report and close the Report Designer. Add a button to the form. And click event for it:

1
2
3
4
5
6
7
8
9
10
11
private void Run_Click(object sender, EventArgs e)
 
 {
 
 report1.Load("D://Reports//Simple.frx");
 
 report1.Prepare();
 
 report1.ShowPrepared();
 
 }

 Here, everything is banal. I have uploaded created earlier report. Then prepared it and showed.

And now, add the event CustomCalc for the report1 object:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
 private void report1_CustomCalc(object sender, FastReport.CustomCalcEventArgs e)
 
 {
 
 if (e.CalculatedObject.Equals("Roberto") )
 
 {
 
 e.CalculatedObject = "Test Name";
 
 }
 
 }

 Here we intercept the needed data and replaces them. All data passes through CalculatedObject object during construction of the report. We catch the needed information "Roberto". And replace them.

You can replace the entire data field. In this case, the condition would look like this:

1
if (e.Expression.IndexOf("employee.FirstName") != -1)

 We wrote the code for the data substitution directly in the event handler CustomCalc. You can also assign the event handler directly in the code, for example in MVC application. With a convenient location in the application code we write:

1
report1.CustomCalc += FReport_CustomCalc;

  And the event handler:

1
2
3
4
5
6
7
8
9
10
11
12
13
private void FReport_CustomCalc(object sender, CustomCalcEventArgs e)
 
 {
 
 if (e.Expression.IndexOf("Employees.FirstName") != -1)
 
 { 
 
 e.CalculatedObject = "Test Name";
 
 }
 
 }

 Run the application. Click the button and see our report:

 

Let's compare this screenshot with one that was made earlier. As you can see, the first entry and the name of the employee Roberto put in a condition and has been replaced by Test Name.

Thus, we have a way to replace some of the data in the report. It probably will be used at sophisticated users of FastReport.

about product download buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Contact us

© 1998-2022 by Fast Reports Inc.

  • Privacy Policy