Declined
Last Updated: 05 Aug 2016 09:27 by ADMIN
ADMIN
Hristo
Created on: 20 Jun 2016 10:04
Category: DataEntry and DataLayout
Type: Bug Report
1
FIX. RadDataEntry - the selected item in a custom RadDropDownList editor is always the first disrespecting its bound index
Duplicated: http://feedback.telerik.com/Project/154/Feedback/Details/138793-fix-raddataentry-incorrectly-mapped-value-for-the-first-item-when-using-raddro

How to reproduce:
 public partial class Form1 : Form
    {
        List<Product> productList;
        List<Supplier> suplierList;
        BindingSource productsBinding;

        public Form1()
        {
            InitializeComponent();

            radDataEntry1.EditorInitializing += radDataEntry1_EditorInitializing;
            radDataEntry1.BindingCreating += radDataEntry1_BindingCreating;
            radDataEntry1.BindingCreated += radDataEntry1_BindingCreated;

            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;
            radBindingNavigator1.BindingSource = productsBinding;
            radDataEntry1.DataSource = productsBinding;
        }

        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;
            }
        }

        void radDataEntry1_BindingCreating(object sender, Telerik.WinControls.UI.BindingCreatingEventArgs e)
        {
            if (e.DataMember == "SupplierID")
            {
                e.PropertyName = "SelectedValue";
            }
        }

        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;
        }

        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;
                }
            }
        }
    }

Workaround: handle the Shown event of the form and manually sync the the selected item in the editor with a cached initial indexprotected override void OnShown(EventArgs e)
{
    base.OnShown(e);

    this.radDropDownList1.SelectedIndex = initialIndex - 1;
}

0 comments