logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • Pre-registration of data sources before create a new report
  • Want to generate tables for a user - Excel or OpenOffice Calc?

    October 8, 2020

    Tables. For centuries, they have been used to present similar data for record-keeping, counting amounts,

    read more
  • How to select the top values in a matrix

    April 22, 2021

    The article is relevant until version 2022.1. FastReport .NET has a great tool for displaying data

    read more
  • How to protect your PDF?

    November 30, 2020

    On the Data protection day, we decided to prepare an article about the PDF documents

    read more
  • Copying the Bands from One Report to Another with All the Contents

    March 31, 2021

    Sometimes there is a need to use parts of one report in another. In simple

    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

Pre-registration of data sources before create a new report

April 30, 2016

In order to send a data source to a report it must previously be pre-registered in the report. Then, within the report select an available source from the list and only after that - start to work. It would be great if the data source could be available to a paste when you open the report designer. Better yet, if it was already selected in the report designer. In this case, you could immediately begin to develop a report, not worrying about the data.

Such an approach would avoid the routine work during the extensive report development.

Make registration of a data source and its automatic choice in a report at the launch of the designer - not a difficult task. The main problem is to keep the registered data source when creating a new report using the File menu.

The essence of the method that I want to introduce - to intercept the process of creating a new report by using the File menu.

Let's consider the following example. Create an application with a form and a single button.

The required for work libraries are:

1
2
3
4
5
using FastReport;
using FastReport.Utils;
using FastReport.Data;
using FastReport.Design;
using FastReport.Wizards;

Declare the data source and then  create it:

1
2
3
4
5
6
private DataSet FDataSet;
private void CreateDataSource()
 {
 FDataSet = new DataSet(); 
 FDataSet.ReadXml(Environment.CurrentDirectory + "//nwind.xml");
 }

In this case, I use XML database from the FastReport .Net package.

Create a method of data source registration :

1
2
3
4
5
6
7
8
9
10
 private void RegisterData(Report FReport)
 {
 FReport.RegisterData(FDataSet, "NorthWind");
 
 // activate all data sources by default
 foreach (DataSourceBase source in FReport.Dictionary.DataSources)
 {
 source.Enabled = true;
 }
 }

Here, the loop iterates through all the data sources that are registered in the report and activates them. Thus they will be immediately available in the data window.
Call an event handler of starting Report Designer:

1
2
3
4
private void DesignerSettings_DesignerLoaded(object sender, EventArgs e)
 {
 (sender as Designer).cmdNew.CustomAction += new EventHandler(cmdNew_CustomAction);
 }

Add a custom handler for the event of creation the new report from the File menu.

Now we need to write the custom handler. It will create a new, blank report with already added data source:

1
2
3
4
5
6
7
8
9
10
11
12
void cmdNew_CustomAction(object sender, EventArgs e)
 {
 Designer designer = sender as Designer;
 
 //StandardReportWizard wizard = new StandardReportWizard(); // you can use any wizard form package
 BlankReportWizard wizard = new BlankReportWizard();
 wizard.Run(designer);
 
 RegisterData(designer.Report);
 // refresh data tree view
 designer.SetModified(this, "EditData");
 }

Here we create an instance of a blank report or run the "standard report wizard." It's your choice. Then open a new report in the designer. Re-register a data source and update the list in the data tree.

It remains to write the handler pressing: 

1
2
3
4
5
6
7
8
9
10
 private void button1_Click(object sender, EventArgs e)
 {
 Report FReport = new Report();
 Config.DesignerSettings.DesignerLoaded += DesignerSettings_DesignerLoaded;
 CreateDataSource(); 
 
 // FReport.Load("myreport.frx"); // load report
 RegisterData(FReport); // register data before design
 FReport.Design();
 }

Create a copy of the report object. Assign a handler of loading report designer, which we have written, instead of the standard one. Create a data source. Now you can download the report, or not do it. Then it will be created empty report. Before calling the designer is required to register the data.

Now, with the launch of the designer, the database tables will be displayed immediately in the "Data" window. Also when creating a new report from the File menu, the data source will be added.

In this article I showed you how to intercept the process of creating a new report, if to create it via the File menu. The same principle can override other actions of the designer, such as Save.

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