logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • The way to add a data field to a matrix row
  • FastReport .NET packages and .NET 5.0

    December 17, 2020

    UPD: Applies to the versions of FastReport .NET before 2022.2. License packages are now available

    read more
  • How to use Online Designer in ASP .NET Core

    January 17, 2018

    One of the novelties by FastReport .NET 2018 was the adaptation of OnlineDesigner to the

    read more
  • How to use WebReport with ASP .NET Web Core application

    January 17, 2018

    Recently FastReport introduced a new library under the .NET - FastReport Core platform. This is

    read more
  • How to make report inheritance in FastReport.NET

    January 29, 2021

    When you are tasked with creating a large number of reports within one corporate style,

    read more
  • FastCube - High-Speed OLAP Cube Engine and Pivot Grid

    February 29, 2020

    It is difficult to imagine data analysis without OLAP (On-Line Analytical Processing) technology. Although there

    read more

The way to add a data field to a matrix row

October 8, 2018

In this article, we'll have a look at the way to create a dynamic matrix that is populated from the report's script code. The peculiarity of this matrix is that in addition to the data added from the script, we will insert the data field in the report cell using a text object.

Suppose you create a matrix with a variable number of columns, which will be added depending on any conditions, but some of the data you have is constant. They are always filled. It would be nice just to put these data fields simply in the matrix, and the remaining cells should be filled from the code. Despite the fact that the filling of the matrix data is provided only in two ways (from the code or automatically, the data fields) we will match them.

In fact, the technology is very simple. The data field is simply inserted into the cell as a separate text object. However, this is not all. When you add data to the matrix in the report, you must add the row number from the data set.

Let's have a look at the example.

Create a report and add the matrix to the "Data" band. Connect the data source - the demonstration database from the delivery, the Employees table.

The matrix template looks like this:

In the cell with a value of 2, we added a text object. In it, select the field Employees.LastName. This is exactly the "static" field about which we have spoken in above.

Create the AfterData event handler for the matrix.

1
2
3
4
5
6
7
8
9
10
11
12
13
private void Matrix1_AfterData(object sender, EventArgs e)
 {
 DataSourceBase rowData = Report.GetDataSource("Employees"); // we get the data source Employees.
 Matrix1.DataSource = rowData; // assign it to the DataSource matrix property 
 
 rowData.Init(); // initialize the data source
 // we go through all records of the data source
 while (rowData.HasMoreRows)
 { 
 Matrix1.Data.AddValue(new Object[] {"Phone" }, new Object[] { (string)Report.GetColumnValue("Employees.City"), (string)Report.GetColumnValue("Employees.FirstName")}, new Object[] {(string)Report.GetColumnValue("Employees.HomePhone") }, Report.GetDataSource("Employees").CurrentRowNo); // add another record
 rowData.Next(); //get the next record
 }
 }

 It is clear from the comments that when you add a data string, we define the title of Phone. Then we insert the data in order: city, name and phone. And also, we need to transfer the data line number to insert the last name from the current data record.

Now run the report:

 

As you can see, you can make it easier for yourself and not add all the necessary data in the report script, but simply place them in the matrix template using a text object.

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