Step 3: Binding a ListBox to the DataSet

To make the chart data more readable, a listbox is required to be added to filter the categories from the data.

Perform the following steps to filter the categories from the data:

  1. From the Visual Studio Toolbox, double-click the ListBox control to add it to the form.
  2. Dock the ListBox control to the left of the FlexChart control so it appears like the following:

    <IMAGE>
  3. Select the ListBox control, and then click on its smart tag.
  4. Select Use Data Bound items.
  5. In the Data Source drop-down listbox, select Categories from Other Data Sources>Project Data Sources>categoriesDataSet.

    <IMAGE>
  6. Select CategoryName in the Display Member drop-down listbox.
  7. Double-click on the ListBox control to generate a listbox1_SelectedIndexChanged event.
  8. Add the following code in the listbox1_SelectedIndexChanged event to filter the CategoryID to the listbox when the user selects a category item:
    Title Text
    Copy Code
    Type your code here.
  9. In the Form1_Load event, add the following code to force the new calculation after the refill so the first category of product items, Beverages, appears rather than all of the unfiltered categories:

    Title Text
    Copy Code
    Type your code here.
  10. Run the application and select a category from the listbox to observe the chart filter the data.

The listbox is bound to the dataset successfully, as shown below:

<IMAGE>