Share via


Tutorial: Filtering Data Using Selection Formulas

Introduction

Selection formulas are used to filter records that you want to display on a Crystal report. To write selection formulas, you can use the Basic syntax or the Crystal syntax.

In this tutorial, you create a selection formula to filter customer records where the Last Year's Sales field is greater than a specific value, and the Customer Name field is compared to another string. A DropDownList (Web) or ComboBox (Windows) control selects a comparison operator for the Customer Name field. You can choose to display customer names that are equal to, less than, greater than, less than or equal to, greater than or equal to, or not equal to the string value that you have specified.

The formula is passed as a string variable to the SelectionFormula property of the CrystalReportViewer class. Once the property is set, the Crystal report that binds to the CrystalReportViewer control is filtered before it is displayed.

This tutorial can also be completed with classes of the CrystalReportViewer object model, although the ReportDocument object model is preferred. For more information on which object model to use, see Which Object Model Should I Use?.

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 files for each sample code version are stored in the following folders:

  • C# Web Site: CS_Web_RDObjMod_SavedDataSelectionFormula
  • C# Windows Project: CS_Win_RDObjMod_SavedDataSelectionFormula
  • Visual Basic Web Site: VB_Web_RDObjMod_SavedDataSelectionFormula
  • Visual Basic Windows Project: VB_Win_RDObjMod_SavedDataSelectionFormula

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

In this section: