Display a Progress for Report Building

This example shows how to display a custom progress for report building. Displaying the progress bar can be useful for complex reports, or reports with large amounts of data. You can use the Rendering event of the report object:

void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
DataSet data = new DataSet();
data.ReadXml("..\\..\\Data\\Demo.xml");

report.RegData(data);
using (var stream = Assembly.GetExecutingAssembly().
GetManifestResourceStream("SampleProgress.Master-Detail-Subdetail.mrt"))
{
report.Load(stream);
}

report.Compile();
report.CompiledReport.Rendering += new EventHandler(CompiledReport_Rendering);

report.Render(false);
}

void CompiledReport_Rendering(object sender, EventArgs e)
{
if (label1.InvokeRequired)
label1.Invoke((EventHandler)delegate
{
label1.Text = report.StatusString;
});
else
label1.Text = report.StatusString;
}


To build a report you can use the thread. The button1_Click event adds necessary handlers and starts the thread. After rendering, the report will be shown in the viewer:

private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
backgroundWorker1.RunWorkerAsync();

label1.Text = "";
label1.Visible = true;
progressBar1.Visible = true;

while (backgroundWorker1.IsBusy)
Application.DoEvents();
}

void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
label1.Visible = false;
progressBar1.Visible = false;

report.Show();
}


In the screenshot below you can see the result of the sample code.

Sample Progress