Change The Editor To a Bound RadDropDownList
This article will walk you through the process of changing the default editor to a bound drop down list, where the current value corresponds to a value within the drop down list data source. The case where the corresponding values are nullable is also handled.
Figure 1: Custom Editor

1. First you can subscribe to the BindingCreating, BindingCreated and EditorInitializing events of RadDataEntry (please note that this should be done before the data entry control is being data bound).
Subscribe to Events
radDataEntry1.EditorInitializing += radDataEntry1_EditorInitializing;
radDataEntry1.BindingCreating += radDataEntry1_BindingCreating;
radDataEntry1.BindingCreated += radDataEntry1_BindingCreated;
radDataEntry1.DataSource = productsBinding;2. In the EditorInitializing event handler, you will be able to change the automatically generated editor with RadDropDownList. In addition, you should set it up as needed. In this case we will set the DataSource, DisplayMember and ValueMenber properties.
Change Default Editor
RadDropDownList radDropDownList1;
void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
{
if (e.Property.Name == "SupplierID")
{
radDropDownList1 = new RadDropDownList();
radDropDownList1.DataSource = suplierList;
radDropDownList1.ValueMember = "SupplierID";
radDropDownList1.DisplayMember = "CompanyName";
e.Editor = radDropDownList1;
}
}3. In order the values to be synchronized correctly, the bound property should be set in the BindingCreating event handler. In this case it should be set to the SelectedValue property.
Map Property
void radDataEntry1_BindingCreating(object sender, Telerik.WinControls.UI.BindingCreatingEventArgs e)
{
if (e.DataMember == "SupplierID")
{
e.PropertyName = "SelectedValue";
}
}4. When the data source is using nullable values in order the user to be able to change the current value via the drop down list, the result value should be manually parsed. This can be done in the binding's Parse event. You can subscribe to this event in the BindingCreated event handler (in order this event to fire the formatting should be enabled).
Enable Formatting
void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
{
if (e.DataMember == "SupplierID")
{
e.Binding.FormattingEnabled = true;
e.Binding.Parse += new ConvertEventHandler(Binding_Parse);
}
}
private void Binding_Parse(object sender, ConvertEventArgs e)
{
int tmpvalue;
int? result = int.TryParse(e.Value.ToString(), out tmpvalue) ? tmpvalue : (int?)null;
e.Value = result;
}To make the example complete you can use the following classes.
Data Models
public class Product
{
private int? _supplierID;
private string _productName;
public Product(int? supplierID, string productName)
{
this._supplierID = supplierID;
this._productName = productName;
}
public int? SupplierID
{
get
{
return this._supplierID;
}
set
{
this._supplierID = value;
}
}
public string ProductName
{
get
{
return this._productName;
}
set
{
this._productName = value;
}
}
}
public partial class Supplier
{
private int? _supplierID;
private string _companyName;
public Supplier(int? supplierID, string companyName)
{
this._supplierID = supplierID;
this._companyName = companyName;
}
public int? SupplierID
{
get
{
return this._supplierID;
}
set
{
this._supplierID = value;
}
}
public string CompanyName
{
get
{
return this._companyName;
}
set
{
this._companyName = value;
}
}
}You can initialize the data sources in the Form’s constructor.
Initialize Data
List<Product> productList;
List<Supplier> suplierList;
BindingSource productsBinding;
public ChangeEditorToDropDownList()
{
InitializeComponent();
productList = new List<Product>();
suplierList = new List<Supplier>();
productList.Add(new Product(1, "Chai"));
productList.Add(new Product(2, "Chang"));
productList.Add(new Product(3, "Aniseed Syrup"));
productList.Add(new Product(4, "Chef Anton's Gumbo Mix"));
productList.Add(new Product(5, "Tofu"));
productList.Add(new Product(null, "Sir Rodney's Marmalade"));
productList.Add(new Product(6, "Boston Crab Meat"));
productList.Add(new Product(5, "Chartreuse verte"));
productList.Add(new Product(2, "Ravioli Angelo"));
productList.Add(new Product(4, "Perth Pasties"));
suplierList.Add(new Supplier(1, "Exotic Liquids"));
suplierList.Add(new Supplier(2, "New Orleans Cajun Delights"));
suplierList.Add(new Supplier(3, "Tokyo Traders"));
suplierList.Add(new Supplier(4, "Norske Meierier"));
suplierList.Add(new Supplier(5, "New England Seafood Cannery"));
suplierList.Add(new Supplier(6, "Leka Trading"));
productsBinding = new BindingSource();
productsBinding.DataSource = productList;
}