logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • ru
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • The way to add a data field to a matrix row
  • Vector graphics in FastReport.Net 2019.4

    July 29, 2019

    Back in FastReport.Net 2018, entry-level vector graphics appeared in the reports. These were polygons and

    read more
  • How to display a sub-report based on conditions of the parent report

    January 8, 2020

    Many modern report generators allow you to embed another report, the so-called sub-report. Why would

    read more
  • Customizing the report designer

    May 31, 2020

    Report designer is replete with lots of features that many users do not use. Sometimes

    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 make custom ToolBar in report preview

    January 8, 2020

    Most report generators have a report-viewing mode with a toolbar from which you can make

    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
Head of QA
.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
  • Our team
  • Contact us

© 1998-2021 by Fast Reports Inc.

  • Privacy Policy