ComboBox cell is a common way of providing the user with a well-defined list of possible values in the form of a drop-down list. FlexGrid provides this multi-option editor in various forms such as dropdown list, dropdown combo, ellipsis button or a textbox with ellipsis button.
Default ComboBox | Multi-column ComboBox | ComboBox with custom BackColor | ComboBox with Images |
---|---|---|---|
In FlexGrid, you can create a dropdown list by creating a string containing all the choices separated by pipe characters (for example, "True|False|Don't know") and assign it to the ComboList property of Row or Column object. This causes the grid to display a drop-down button next to the cell. The user can click the dropdown button (or press F2) to display the list of choices available for that cell.
Another common situation is where cells have a list of common values, but users should be allowed to type a custom value as well. This can be accomplished with drop-down combos, a combination of text box and drop-down list. In FlexGrid, you can create combos by starting the choice list with a pipe character (for example "|True|False|Don't know"), and then assign it to the ComboList property.
Following code shows how to create a dropdown list or combo editor in the WinForms FlexGrid.
The ComboList property can also be set using the Combo List dialog at design time. To access the Combo List dialog:
In FlexGrid, you can also display multiple columns in a ComboBox using the MultiColumnDictionary class. This class implements the IC1MultiColumnDictionary interface and has multiple overloads. These overloads let you specify the data source object, the key column, columns that are to be displayed in multiple columns, and the column to be displayed when ComboBox is closed.
Display a multi-column combobox in a WinForms FlexGrid column using the code below.
Note that the above code uses the data source object dt to supply data to the grid. You can set up the data source as per your requirements.
To set a ComboBox having display values different from the actual values, you need to use the C1ComboBox as editor and leverage its ItemsDisplayMember and ItemsValueMember properties. For instance, the example below uses country names as display values while actual value is the dialing code of the corresponding country.
Following code shows how to set the mapped data in combobox column of the WinForms FlexGrid.
To set the height and width of combo box dropdown, you need to assign an instance of ComboBox as an editor and then set the DropDownHeight and DropDownWidth property of that instance.
Use the code below to specify the height and width of the combobox to be displayed in the WinForms FlexGrid.
To change the background color or font color of the ComboBox list, create an instance of ComboBox to assign it as editor. Then, set the BackColor and ForeColor property of that instance.
Customize combobox in the WinForms FlexGrid by using the code below.
To display images in the ComboBox list, you need to use the C1ComboBox as an editor and leverage its ItemsImageList property. This property is of type ImageList class that acts as a container for the images which are stored in its Images collection. First, access the images stored in the project resources through the ResourceManager.GetResourceSet method and create a collection of mapping between images and its corresponding names. The collection acts as a data source for ComboBox. Now, create an instance of the ImageList class, add images to its Images collection from data source and assign that instance of ImageList class to the ItemsImageList property to render images in the ComboBox list.
Following code shows how to display images in the combobox lists of WinForms FlexGrid.
To set the number of items to be displayed in a combo box, you can use ComboBox.MaxDropDownItems property.
Use the code below to limit the number of items to be displayed in combobox list of the WinForms FlexGrid.
To sort the items in the ComboBox dropdown list, you can use the C1ComboBox as editor and call the Sort method to sort the dropdown items getting displayed in the ComboBox.
To display sorted items in comboboxlist of the WinForms FlexGrid, use the code below.
To get the selected index or value of the selected item, you can use the SelectedIndex property or SelectedItem property of the ComboBoxEditor class. The example below uses the ComboCloseUp event to show a message box displaying the selected index and the selected item.
Use the code below to fetch the index and value of selected item in combobox list of the WinForms FlexGrid.