Export (0) Print
Expand All

Populating the DropDownList ComboBox Control

Visual Studio 2005

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   In Visual Basic, remember to change both the opening and closing signature. In C#, delete the constructor.
  5. Enter the following enum values.
    [Visual Basic]
        EqualTo
        GreaterThan
        GreaterThanOrEqualTo
        LessThan
        LessThanOrEqualTo
        NotEqualTo
    [C#]
        EqualTo,
        GreaterThan,
        GreaterThanOrEqualTo,
        LessThan,
        LessThanOrEqualTo,
        NotEqualTo
  6. Open the Web or Windows form in Design View.
  7. From the View menu, click Code.
  8. 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.
      [Visual Basic]
      operatorValueList.DataSource = System.Enum.GetValues(GetType(CeComparisonOperator))
      operatorValueList.DataBind()
      [C#]
      operatorValueList.DataSource = System.Enum.GetValues(typeof(CeComparisonOperator));
      operatorValueList.DataBind();
    • In a Windows project, place only the DataSource property assignment within the useDefaultValues conditional block.
      [Visual Basic]
      operatorValueList.DataSource = System.Enum.GetValues(GetType(CeComparisonOperator))
      [C#]
      operatorValueList.DataSource = System.Enum.GetValues(typeof(CeComparisonOperator));
      Note   In a Windows project, you do not need to call a DataBind() method.
  9. At the bottom of the ConfigureCrystalReports() method, assign the selectionFormula string to the Text property of the formula Label control.
    [Visual Basic]
    formula.Text = selectionFormula
    [C#]
    formula.Text = selectionFormula;
  10. Compile and view the application.

    The operator list and all other controls should be correctly displayed.

  11. Close your browser.

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

Continue to Retrieving Selections from the Control.

See Also

Tutorial: Filtering Data Using Selection Formulas | Tutorials and Sample Code | Tutorials' Sample Code Directory

Show:
© 2014 Microsoft