I resume this old post since I have a situation very similar to the one described by DImitiri earlier.
I reuse his sample code.
I've seen that "Binding_Parse" is not fired the first time I select another item in the DropDownList, while all the other times it is correctly executed.
I also set an "OnSelectedValueChanged" event on the combobox and I see that the parameters newValue and oldValue are always correct, even the first time.
Is this a known issue? Or is there a way to force the Binding when OnSelectedValueChanged is raised?
namespace TestDDL
{
public partial class Form1 : RadForm
{
private List<
Supplier
> supplierList;
public Form1()
{
InitializeComponent();
suplierList = new List<
Supplier
>();
suplierList.Add(new Supplier(1, "(1) Exotic Liquids"));
suplierList.Add(new Supplier(2, "(2) New Orleans Cajun Delights"));
suplierList.Add(new Supplier(3, "(3) Tokyo Traders"));
suplierList.Add(new Supplier(4, "(4) Norske Meierier"));
suplierList.Add(new Supplier(5, "(5) New England Seafood Cannery"));
suplierList.Add(new Supplier(6, "(6) Leka Trading"));
// I create the record here to be displayed in the RadDataEntry form
var record = new Record();
record.SupplierItem = 3; // I want the drop down list to initially display item 3 or 'Tokyo Traders'
// This is what is not working ...
radDataEntry1.DataSource = record;
}
void radDataEntry1_EditorInitializing(object sender, Telerik.WinControls.UI.EditorInitializingEventArgs e)
{
if (e.Property.Name == "SupplierItem")
{
var radDropDownList1 = new RadDropDownList();
radDropDownList1.DataSource = suplierList;
radDropDownList1.ValueMember = "SupplierID";
radDropDownList1.DisplayMember = "CompanyName";
radDropDownList1.Parent = this;
e.Editor = radDropDownList1;
}
}
void radDataEntry1_BindingCreating(object sender, Telerik.WinControls.UI.BindingCreatingEventArgs e)
{
if (e.DataMember == "SupplierItem")
{
e.PropertyName = "SelectedValue";
}
}
void radDataEntry1_BindingCreated(object sender, BindingCreatedEventArgs e)
{
if (e.DataMember == "SupplierItem")
{
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;
}
}
public class Record
{
public int SupplierItem { get; set; }
}
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;
}
}
}
}