Cascading ComboBoxes in RadGridView
Product Version | Product | Author | Last modified |
---|---|---|---|
2012.3.1017 | RadGridView for WinForms | Stefan Stefanov | Dec 15, 2012 |
HOW-TO
This article demonstrates how you can implement the popular 'cascading combos' scenario where the range of options available in a drop-down list of a combo column depend on the choice made by the end-user in another combo column for the same row.
SOLUTION
1.Lets create two classes that are going to be used in this example. The first is called FoodType and the other one is Food. As the classes names imply, we will have two combo boxes - the first will allow choosing the type of the food (i.e. Fruits and Vegetables) and the second will allow for choosing the food itself (i.e Cucumbers, Bananas etc):
2.Create three BindingLists (as fields) that will hold the necessary data and populate them
3.Create the GridViewComboBoxColumn columns and make their settings. The first column is responsible for the food types, while the second for the food according to the food type:
4.Last subscribe for the CellEditorInitialized event of RadGridView, where modifications for the dynamic editor will be placed:
5.Last, but not least, we should subscribe to the CellValueChanged event which is fired after the editing process of a cell is finished and there is a new value committed to the cell. In the CellValueChanged event handler we should check if the cell for which the value has been changed is in the column FoodType. If 'yes', this means that the value of the Food cell in the same row is not valid anymore (for example, you cannot have "Vegetable" entered for the FoodType leaving the value of the Food cell to "Apple") and we should delete it:
The result is:
You can download a complete VB and C# project from the following link.