|
Article relates to
|
Q3 2010 SP 1
|
|
Created by
|
Stefan Stefanov
|
|
Last modified
|
January 3, 2011
|
|
Last modified by
|
|
HOW-TO
This article demonstrates how you can make a RadComboBoxEditor in GridViewComboBoxColumn dependant on the value of another cell.
SOLUTION
1. Lets created 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 speak we will have two combo boxes - the first will allow choosing the type of the food (i.e. Fruits and Vegetables) and the second the food itself (i.e Cucumbers, Bananas etc):
2. Create three BindingLists (as fields) that will hold the necessary data and populate them
BindingList<Food> fullList;
BindingList<Food> fruitsList;
BindingList<Food> vegetablesList;
public Form1()
{
InitializeComponent();
fullList = new BindingList<Food>();
fullList.Add(new Food(0, "Onion"));
fullList.Add(new Food(1, "Cucumber"));
fullList.Add(new Food(2, "Tomato"));
fullList.Add(new Food(3, "Peach"));
fullList.Add(new Food(4, "Banana"));
fullList.Add(new Food(5, "Grape"));
fruitsList = new BindingList<Food>();
fruitsList.Add(fullList[3]);
fruitsList.Add(fullList[4]);
fruitsList.Add(fullList[5]);
vegetablesList = new BindingList<Food>();
vegetablesList.Add(fullList[0]);
vegetablesList.Add(fullList[1]);
vegetablesList.Add(fullList[2]);
BindingList<FoodType> typesList = new BindingList<FoodType>();
typesList.Add(new FoodType(0, "Vegetables"));
typesList.Add(new FoodType(1, "Fruits"));
GridViewComboBoxColumn foodType = new GridViewComboBoxColumn();
foodType.FieldName = "FoodType";
this.radGridView1.Columns.Add(foodType);
foodType.DataSource = typesList;
foodType.Width = 100;
foodType.DisplayMember = "FoodTypeName";
foodType.ValueMember = "FoodTypeID";
GridViewComboBoxColumn food = new GridViewComboBoxColumn();
food.FieldName = "Food";
this.radGridView1.Columns.Add(food);
food.DataSource = fullList;
food.Width = 100;
food.DisplayMember = "FoodName";
food.ValueMember = "FoodID";
}
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:
The result is:
