In ActiveReports for .NET 3.0, you can use a Web Service that returns the content of an ActiveReport to show in the Windows Forms viewer control.
This walkthrough illustrates how to create a Windows client application that returns the content of an ActiveReport in the Windows Forms viewer.
This walkthrough builds on the ActiveReports Document Web Service walkthrough and is split up into the following activities:
- Creating a Visual Studio project
- Adding the ActiveReports Windows Forms viewer control to the project
- Adding a web reference to the project
- Adding the code to set the viewer's document property to the content returned by the ActiveReports Document Web Service
- Running the project
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have finished this walkthrough, you will have a report that looks similar to the following.
Creating a Visual Studio project
To create a Visual Studio project
- From the File menu, select New > Project.
- Select Windows Application in the Templates window of the New Project dialog.
- Change the name of the application to ARDocumentClient.
- Click OK to open the project.
Adding the ActiveReports viewer control to the Windows Form
To add the ActiveReports viewer control
- Drag and drop the ActiveReports viewer control from the appropriate toolbox to the Windows Form.
- Change the Dock property for the viewer control to Fill.
Adding a web reference to the project
To add a web reference
- From the Project menu, select Add Web Reference.
- Type in the address of the .asmx file for the ActiveReports Document Web Service you created in the previous walkthrough. The address should be similar to http://localhost/ARDocumentWS/Service1.asmx.
- Click the Add Reference button when the Web Service is recognized.
Adding the code needed to set the viewer's document property to the content returned by the ActiveReports Document Web Service
To write the code in Visual Studio 2003
- Double-click on Form1 to create an event-handling method for the Form1_Load event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim ws As New localhost.ARDocumentWS() Me.Viewer1.Document.Content = ws.GetProductsReport() End Sub //C# private void Form1_Load(object sender, System.EventArgs e) { localhost.ARDocumentWSvb ws = new localhost.ARDocumentWSvb(); this.viewer1.Document.Content = ws.GetProductsReport(); }
To write the code in Visual Studio 2005
- Double-click on Form1 to create an event-handling method for the Form1_Load event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim ws As New localhost.Service Me.Viewer1.Document.Content = ws.GetProductsReport() End Sub //C# private void Form1_Load(object sender, System.EventArgs e) { localhost.Service ws = new localhost.Service(); this.viewer1.Document.Content = ws.GetProductsReport(); }
Running the project
To run the project
- Press F5 to run the project.