Setting Data Source

Report data sources are set in the DataSources properties of the ReportManager class. This property has a PerpetuumSoft.Reporting.Components.ObjectPointerCollection type. This class is a collection of objects bound to string keys.

To set report data sources via the property editor, select ReportGenerator object and in the Property grid, click the button of the DataSource property. There will appear a Data Binding form shown in the picture below.

“Edit” button runs editor for the selected data source in the Data Binding List, “Delete” button deletes selected data source, “Close” button closes Data Binding Editor.

To add a new data source, click “Add” button and you will see form shown in the picture below.

Name field is used to enter name under which data source will be available in the report. Value field is used to select name of the object used in your application that is a data source itself. As a result the InitializeComponent() method will be added to the code shown below.

(C#)

this.reportManager.DataSources = 
  new PerpetuumSoft.Reporting.Components.ObjectPointerCollection(
    new string[] {"AccountsDataSet", "CustomersByCity"}, 
    new object[] {this.accountsDataSet, this.customersByCity});

(VB)

Me.reportManager.DataSources = 
  New PerpetuumSoft.Reporting.Components.ObjectPointerCollection(
    New String() {"AccountsDataSet", "CustomersByCity"}, 
    New Object() {Me.accountsDataSet, Me.customersByCity })

To make data source display in the Value list, it should be descendant from the System.ComponentModel.Component class.

To add data source from code, you can use Add method of the ObjectPointerCollection class of the Item property:

(C#)

reportManager.DataSources.Add("DataSourceName", dataSource);

(VB)

reportManager.DataSources.Add("DataSourceName", dataSource)

or

(C#)

reportManager.DataSources["DataSourceName"] = dataSource;

(VB)

reportManager.DataSources("DataSourceName") = dataSource

Add method accepts two parameters: data source name by which it will be available in the report and the data source itself. In the same way you can set name and data source when using Item property.

Report data sources can be loaded directly in the template.

Add Feedback