Share via

Tutorial: Filtering Data Using Selection Formulas


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 and the Crystal syntax. For more information about how to write selection formulas, see Formula Reference.

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 ListBox control is used to select 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.

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_CRVObjMod_FilteringData
  • C# Windows project: CS_Win_CRVObjMod_FilteringData
  • Visual Basic Web Site: VB_Web_CRVObjMod_FilteringData
  • Visual Basic Windows project: VB_Win_CRVObjMod_FilteringData

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

In this section: