Quickly begin using ActiveReports by following the steps of some of the most commonly used features. See Install ActiveReports topic to see how to add references to GrapeCity.ActiveReports from nuget.org.
You can add an ActiveReport to a project without using the Visual Studio toolbox, but in order to use the Viewer control, any of the exports, the Designer and related controls, or the WebViewer control, you need to have them in your toolbox.
On installing NuGet packages, the controls are automatically added to the toolbox in Visual Studio 2017 and Visual Studio 2019, in an ActiveReports 14 tab.
If you are using Visual Studio 2013 or Visual Studio 2015, the NuGet packages do not add the controls on the toolbox by default. You need to add the controls manually as follows.
The added control(s) should now display in the tab.
Page Report
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
' Create a new Page report instance Dim pageReport As New GrapeCity.ActiveReports.PageReport() Dim Page As New GrapeCity.ActiveReports.PageReportModel.Page() Dim fixedPage As New GrapeCity.ActiveReports.PageReportModel.FixedPage() ' Add a textbox to your Page report Dim textbox1 As New GrapeCity.ActiveReports.PageReportModel.TextBox() textbox1.Name = "TextBox1" textbox1.Height = "1cm" textbox1.Width = "10cm" textbox1.Left = "2cm" textbox1.Top = "0.5cm" textbox1.Value = "Sample Page Report" Page.ReportItems.Add(textbox1) fixedPage.Pages.Add(Page) pageReport.Report.Body.ReportItems.Add(fixedPage) ' Create a Page document and load it in Viewer Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(pageReport) viewer1.LoadDocument(pageDocument) |
C# code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
// Create a new Page report instance GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(); GrapeCity.ActiveReports.PageReportModel.Page Page = new GrapeCity.ActiveReports.PageReportModel.Page(); GrapeCity.ActiveReports.PageReportModel.FixedPage fixedPage = new GrapeCity.ActiveReports.PageReportModel.FixedPage(); // Add a textbox to your Page report GrapeCity.ActiveReports.PageReportModel.TextBox textbox1 = new GrapeCity.ActiveReports.PageReportModel.TextBox(); textbox1.Name = "TextBox1"; textbox1.Height = "1cm"; textbox1.Width = "10cm"; textbox1.Left = "2cm"; textbox1.Top = "0.5cm"; textbox1.Value = "Sample Page Report"; Page.ReportItems.Add(textbox1); fixedPage.Pages.Add(Page); pageReport.Report.Body.ReportItems.Add(fixedPage); // Create a Page document and load it in Viewer GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport); viewer1.LoadDocument(pageDocument); |
RDL Report
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
' Create a new RDL report instance Dim rdlReport As New GrapeCity.ActiveReports.PageReport() ' Add a textbox to your RDL report Dim textbox1 As New GrapeCity.ActiveReports.PageReportModel.TextBox() textbox1.Name = "TextBox1" textbox1.Height = "1cm" textbox1.Width = "10cm" textbox1.Left = "2cm" textbox1.Top = "0.5cm" textbox1.Value = "Sample RDL Report" rdlReport.Report.Body.ReportItems.Add(textbox1) ' Create a Page document and load it in Viewer Dim rdlDocument As New GrapeCity.ActiveReports.Document.PageDocument(rdlReport) viewer1.LoadDocument(rdlDocument) |
C# code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
// Create a new RDL report instance GrapeCity.ActiveReports.PageReport rdlReport = new GrapeCity.ActiveReports.PageReport(); // Add a textbox to your RDL report GrapeCity.ActiveReports.PageReportModel.TextBox textbox1 = new GrapeCity.ActiveReports.PageReportModel.TextBox(); textbox1.Name = "TextBox1"; textbox1.Height = "1cm"; textbox1.Width = "10cm"; textbox1.Left = "2cm"; textbox1.Top = "0.5cm"; textbox1.Value = "Sample RDL Report"; rdlReport.Report.Body.ReportItems.Add(textbox1); // Create a Page document and load it in Viewer GrapeCity.ActiveReports.Document.PageDocument rdlDocument = new GrapeCity.ActiveReports.Document.PageDocument(rdlReport); viewer1.LoadDocument(rdlDocument); |
Section Report
Visual Basic.NET code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
' Create a new Section report instance Dim sectionReport As New GrapeCity.ActiveReports.SectionReport() ' Create a Detail section sectionReport.Sections.Add(GrapeCity.ActiveReports.Document.Section.SectionType.Detail, "Body") ' Add a textbox to your Section report Dim textbox1 As New GrapeCity.ActiveReports.SectionReportModel.TextBox() textbox1.Name = "TextBox1" textbox1.Height = 1.5F textbox1.Width = 10.0F textbox1.Left = 0.5F textbox1.Top = 0.5F textbox1.Value = "Sample Section Report" sectionReport.Sections(0).Controls.Add(textbox1) ' Load the Section report in the Viewer sectionReport.Run() viewer1.LoadDocument(sectionReport) |
C# code. Paste INSIDE the Form Load event. |
Copy Code
|
---|---|
// Create a new Section report instance GrapeCity.ActiveReports.SectionReport sectionReport = new GrapeCity.ActiveReports.SectionReport(); // Create a Detail section sectionReport.Sections.Add(GrapeCity.ActiveReports.Document.Section.SectionType.Detail, "Body"); // Add a textbox to your Section report GrapeCity.ActiveReports.SectionReportModel.TextBox textbox1 = new GrapeCity.ActiveReports.SectionReportModel.TextBox(); textbox1.Name = "TextBox1"; textbox1.Height = 1.5F; textbox1.Width = 10F; textbox1.Left = 0.5F; textbox1.Top = 0.5F; textbox1.Value = "Sample Section Report"; sectionReport.Sections[0].Controls.Add(textbox1); // Load the Section report in the Viewer sectionReport.Run(); viewer1.LoadDocument(sectionReport); |
The first thing you probably want to do when you create a report is to add data. You can accomplish this in a variety of ways, depending on the type of report you are using.
With page reports or RDL reports, you basically connect to a data source, and then add a dataset. You can also create a shared data source if you use the same one for many reports. For information on how to perform these tasks, see Work with Data in the How To section. For more information on each item in the associated dialogs, see Data Sources and Datasets in the Concepts section.
For more advanced ways to connect data, see the Walkthroughs section for step by step instructions on using Reports with Stored Procedures, or creating a Custom Data Provider.
With section reports, you bind a report to any of a variety of data sources and select the data using a SQL query or XPath expression in the Data Source Dialog. You can also use code to create an unbound data source or to change the data source at run time. For more information on all of these methods of binding reports to data, see Work with Data in the Section Report How To section.
ActiveReports provides an in-built sample application that includes a report template along with the Viewer control. You learnt about creating a report and viewing it in the preceding sections. With this Windows Forms application you only need to create a report layout and run the application to view the report, effectively skipping the manual process of adding a Viewer and template separately and creating an instance of the report.
Fields provide data to display on a report page. ActiveReports has two types of fields; a bound or database field and a calculated field.
In a section report, once you connect to a data source, bound fields automatically appear under the Fields > Bound node in the Report Explorer. However, you have to add calculated fields manually under the Fields > Calculated node. The following steps guide you through the process.
In a page report or a RDL report, all fields irrespective of their type appear under the corresponding DataSet node in the Report Explorer. To create a calculated field, you can add the new field in the DataSet dialog.
The following steps guide you through the process.