FlexGrid for WinForms
Step 3 of 6: Incorporate Drop-Down Lists
Show AllShow All
Hide AllHide All

Entering data is a tedious and error-prone process. Drop-down lists are great because they minimize the amount of typing you must do, reduce the chance of errors, and increase the consistency of the data.

Let's assume that our tutorial project only involves sales of three products (Applets, Wahoos, and Gadgets), in four regions (North, South, East, and West), and that there are three full-time sales people (Mary, Sarah, and Paula).

To use these lists as drop-downs in the C1FlexGrid control, all you have to do is build strings containing the items in each list (separated by pipe characters) and assign them to the ComboList property of each column. This property can be set either in the designer or in code.

In the Designer

  1. Select the Product column. This will open the Column Tasks menu for the Product column.
  2. Click the ellipsis button in the Combo List box to open the Combo List dialog box.
  3. Enter Applets, Wahoos, and Gadgets as shown below:
  4. Click OK to close the Combo List dialog box.
  5. Select the Region column.
  6. Click the ellipsis button in the Combo List box.
  7. Enter North, South, East, and West as shown below:
  8. Click OK.
  9. Select the Salesperson column.
  10. Click the ellipsis button in the Combo List box.
  11. Enter Mary, Paula, and Sarah as shown below:
  12. Select the Dropdown Combo option.
  13. Click OK.

Alternatively, the ComboList property can be set using the C1FlexGrid Column Editor:

  1. Open the C1FlexGrid Column Editor by selecting Designer in the C1FlexGrid Tasks menu. For details on how to access the C1FlexGrid Column Editor, see Accessing the C1FlexGrid Column Editor.
  2. Select the Productcolumn in the right pane.
  3. In the left pane, set the ComboList property to Applets|Wahoos|Gadgets.
  4. Select the Region column in the right pane.
  5. In the left pane, set the ComboList property to North|South|East|West.
  6. Select the Salesperson column in the right pane.
  7. In the left pane set the ComboList property to |Mary|Paula|Sarah.
  8. Click OK to close the editor.

In Code

To add the combolists, add the following code after the code added in Step 2 of 6: Set Column Types and Formats:

To write code in Visual Basic

To write code in C#

Run the program and observe the following:

Notice how the last ComboList string starts with a pipe (text input cursor). This allows users to type additional names that are not on the list. In other words, these values will be edited using a drop-down combo, as opposed to a simple drop-down list.

Press F5 to run the project again, and then move the cursor around. When you move the cursor to one of the columns that have combo lists, a drop-down button becomes visible. You may click on it to show the list, or simply type the first letter of an entry to highlight it on the list.


See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Product Support Forum |  Documentation Feedback