Adding a local report in WinForms. |
Alex van Buitenen |
This is not a tutorial nor a complete quick reference.
This document is just my personal memo block for C#.
Rightclick Project, Add, New Item.
Choose Reporting, Report
The
.rdlc file is created and opened.
Right click the report, Insert, Page Header
Adjust background color.
Open Report data properties window (View, Report data (Available when .rdlc file is opened))
Add parameter "HeaderText"
Drag Textbox from Toolbox on header.
Click on Textbox. The propertiew window changes from "Textbox" to "Selected text".
Notice that the properties window does not yet conatin a value member.
Righclick the "selected text" and choos "Create Placeholder".
Press fx for Value and pick parameter "Headertext".
Make sure the projects gets compiled, otherwise datasource "Person" will not be available.
Drag Table from ToolBox on body (Dit wordt een "Tablix")
Visual Studio lets you choose a datasource immediately.
Add a Form to the project.
Add a ReportViewer to the Form.
Choose the report in ReportViewer by clicking on the little arrow in the upper rights corner. This results in the porperty "LocalReport.ReportEmbeddedResouce" to be filled.
Fill the reports parameter and datasource, for instance:
using Microsoft.Reporting.WinForms;
private void reportViewer1_Load(object sender, EventArgs e)
{
this.reportViewer1.LocalReport.SetParameters(new ReportParameter("HeaderText", "Persons"));
this.reportViewer1.LocalReport.DataSources[0].Value = GetPersons();
}
private List<Person> GetPersons()
{
List<Person> persons = new List<Person>();
Person piet = new Person("Piet", 30);
Person jan = new Person("Jan", 25);
persons.Add(piet);
persons.Add(jan);
return persons;
}