FlexGrid for WinForms Tutorials > Edit Tutorial > Step 3 of 6: Incorporate Drop-Down Lists |
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.
Alternatively, the ComboList property can be set using the C1FlexGrid Column Editor:
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
Visual Basic |
Copy Code
|
---|---|
' Set up the drop-down lists.C1FlexGrid1. Cols("Product").ComboList = "Applets|Wahoos|Gadgets" C1FlexGrid1.Cols("Region").ComboList = "North|South|East|West" C1FlexGrid1.Cols("Salesperson").ComboList = "|Mary|Paula|Sarah" |
To write code in C#
C# |
Copy Code
|
---|---|
// Set up the drop-down lists. c1FlexGrid1.Cols["Product"].ComboList = "Applets|Wahoos|Gadgets"; c1FlexGrid1.Cols["Region"].ComboList = "North|South|East|West"; c1FlexGrid1.Cols["Salesperson"].ComboList = "|Mary|Paula|Sarah"; |
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.