Share via


Tutorial: Connecting to Object Collections

Introduction

In this tutorial, you create a class that is the type for each object in the object collection. The class will represent stock market information. When you build your Crystal report, this Stock class is accessed from the report wizard much like a database table, but rather than add table columns as fields to display, you add class properties instead.

When the report is first displayed, the report is empty. The report design is complete, but no data is available to populate the report.

Then you create a method that instantiates an ArrayList and adds multiple Stock instances to the ArrayList instance. Each Stock instance has its properties set to unique values. The ArrayList instance is then returned from the method. You will add this information programmatically at design time, and again dynamically at run time.

The returned ArrayList, an object collection, is assigned to the SetDataSource property of the Crystal report. When the report is displayed, each object in the object collection provides one Detail row in the report.

Sample Code

This tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version.

The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows:

  • C# Web Site: CS_Web_Data_ObjectCollection
  • Visual Basic Web Site: VB_Web_Data_ObjectCollection

To locate the folders that contain these samples, see Tutorials' Sample Code Directory.

In this section: