ActiveReports 13
Adding an ActiveReport to a Project
ActiveReports 13 > ActiveReports User Guide > Getting Started > Adding an ActiveReport to a Project

To use ActiveReports in a Visual Studio project, you add one of the included report templates.

To add an ActiveReport to a project

  1. From the Visual Studio Project menu (or Website menu in Web projects), select Add New Item.
  2. Select the type of report that you want to add (for information on the differences, see Report Types): 
    • Section Report (code-based)
    • Section Report (xml-based)
    • Page Report
    • RDL Report

  3. In the Name box, type a name for the report, and click Add. The selected report type is added to your project and opens in the report designer.
Note: When you add a report layout the Viewer assembly (GrapeCity.ActiveReports.Viewer.Win.dll) is not added automatically to the project references. You may need to manually add it in your project if required.

To add an ActiveReport to a project at run time

  1. In Visual Studio, create a new Windows Forms Application or open an existing one.
  2. From the Visual Studio toolbox, drag the Viewer control onto your Windows Form.
  3. Set the Viewer's Dock property to Fill to show the complete Viewer control on the form.
  4. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
  5. Add the following code inside the Form_Load event.

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);    
See Also

Concepts