We have already discussed about using XSD (Typed Dataset) as a datasource for ActiveReports' Section Reports in this article. However, we didn't discuss about how to use it in case of Page Reports. The tricks of the trade remains almost same with some minor changes to make this work.
In case you are not aware of how to create a Typed Dataset then you can go through a quick recap here. Just remember to fill the DataSet so that it does not return empty rows.
Now in order to connect this XSD to the report we will need to use the DataSet provider with the LocateDataSource event. To use the Dataset provider as a report's data source we will need to set up a report definition at runtime, and attach the page document to a LocateDataSourceEventHandler.
Here are the steps that are needed to connect a Page Report to an XSD dataset.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using GrapeCity.ActiveReports;
using GrapeCity.ActiveReports.Document;
using GrapeCity.ActiveReports.Configuration;
namespace WindowsFormsApplication24
{
public partial class Viewer : Form
{
PageDocument runtime;
Northwind.CustomersDataTable table = new Northwind.CustomersDataTable();
NorthwindTableAdapters.CustomersTableAdapter da = new NorthwindTableAdapters.CustomersTableAdapter();
private void LoadReport()
{
FileInfo rptPath = new FileInfo(@"..\\..\\PageReport2.rdlx");
PageReport definition = new PageReport(rptPath);
definition.ConfigurationProvider = new GrapeCity.ActiveReports.Configuration.DefaultConfigurationProvider();
runtime = new PageDocument(definition);
runtime.LocateDataSource += new LocateDataSourceEventHandler(runtime_LocateDataSource);
\\\viewer1.LoadDocument(runtime);
}
void runtime_LocateDataSource(object sender, LocateDataSourceEventArgs args)
{
da.Fill(table);
args.Data = table;
}
public Viewer()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LoadReport();
}
}
Download the attached samples for complete implementation. Download VB Sample Download C# Sample