|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
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
- In Solution Explorer, right-click the project name that is in bold type, point to Add, and then click Add New Item.
- In the Add New Item dialog box, select Class.
- Enter the name "CeComparisonOperator" and then click OK.
- 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.
- Enter the following enum values.[Visual Basic]
EqualTo GreaterThan GreaterThanOrEqualTo LessThan LessThanOrEqualTo NotEqualTo[C#]
EqualTo, GreaterThan, GreaterThanOrEqualTo, LessThan, LessThanOrEqualTo, NotEqualTo
- Open the Web or Windows form in Design View.
- From the View menu, click Code.
- 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.
- In a Web Site, place the DataSource property assignment and the binding within the Not IsPostBack conditional block.
- 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;
- Compile and view the application.
The operator list and all other controls should be correctly displayed.
- 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.