Populating the DropDownList ComboBox Control

The DropDownList control (Web) or ComboBox control (Windows) requires a list of operatorValues (equal, greater than, and so on). The most generic way to populate this control is to provide the list of values as an enumerator.

To populate the DropDownList ComboBox control

  1. In Solution Explorer, right-click the project name that is in bold type, point to Add, and then click Add New Item.

  2. In the Add New Item dialog box, select Class.

  3. Enter the name "CeComparisonOperator" and then click OK.

  4. In the class file, change the word class to enum.

> [!NOTE]
> <P>In Visual Basic, remember to change both the opening and closing signature. In C#, delete the constructor.</P>
  1. Enter the following enum values.

        EqualTo
        GreaterThan
        GreaterThanOrEqualTo
        LessThan
        LessThanOrEqualTo
        NotEqualTo
    
        EqualTo,
        GreaterThan,
        GreaterThanOrEqualTo,
        LessThan,
        LessThanOrEqualTo,
        NotEqualTo
    
  2. Open the Web or Windows form in Design View.

  3. From the View menu, click Code.

  4. In the ConfigureCrystalReports() method, you now populate the operatorValueList instance with values from the CeComparisonOperator enum. This code is placed in a different location, depending on whether you are building a Web Site or a Windows project.

    • In a Web Site, place the DataSource property assignment and the binding within the Not IsPostBack conditional block.

      operatorValueList.DataSource = System.Enum.GetValues(GetType(CeComparisonOperator))
      operatorValueList.DataBind()
      
      operatorValueList.DataSource = System.Enum.GetValues(typeof(CeComparisonOperator));
      operatorValueList.DataBind();
      
    • In a Windows project, place only the DataSource property assignment within the useDefaultValues conditional block.

      operatorValueList.DataSource = System.Enum.GetValues(GetType(CeComparisonOperator))
      
      operatorValueList.DataSource =
      System.Enum.GetValues(typeof(CeComparisonOperator));
      

      Note

      In a Windows project, you do not need to call a DataBind() method.

  5. At the bottom of the ConfigureCrystalReports() method, assign the selectionFormula string to the Text property of the formula Label control.

``` vb
formula.Text = selectionFormula
```

``` csharp
formula.Text = selectionFormula;
```
  1. Compile and view the application.
The operator list and all other controls should be correctly displayed.
  1. Close your browser.

In the next section, you create a method that retrieves selections from this control when the Redisplay Report button is clicked.