Declined
Last Updated: 31 Mar 2014 09:12 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 19 Dec 2013 09:02
Category:
Type: Bug Report
1
FIX. RadDropDownList with DataBindings does not refresh its SelectedValue correctly (compared to ComboBox)
To reproduce:

- add a RadDropDownList , MS ComboBox and a RadButton;

Use the following code:

public partial class Form1 : Form { private List<States> stateslist = new List<States>(); private BindingSource addressBindingSource = new BindingSource(); private BindingSource statesBindingSource = new BindingSource(); public Form1() { InitializeComponent(); addressBindingSource.DataSource = typeof(Address); statesBindingSource.DataSource = typeof(States); stateslist.Add(new States { DisplayName = "California", ID = 1 }); stateslist.Add(new States { DisplayName = "Nevada", ID = 2 }); stateslist.Add(new States { DisplayName = "New York", ID = 1 }); statesBindingSource.DataSource = stateslist; this.radDropDownList1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue",addressBindingSource, "State_ID", true)); this.radDropDownList1.DataSource = statesBindingSource; this.radDropDownList1.DisplayMember = "DisplayName"; this.radDropDownList1.ValueMember = "ID"; this.radDropDownList1.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList; this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", addressBindingSource, "State_ID", true)); this.comboBox1.DataSource = statesBindingSource; this.comboBox1.DisplayMember = "DisplayName"; this.comboBox1.ValueMember = "ID"; this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; } private void radButton1_Click(object sender, EventArgs e) { Address newEntity = new Address(); addressBindingSource.DataSource = newEntity; } } public class States { public int ID { get; set; } public string DisplayName { get; set; } } public class Address { public string Address1 { get; set; } public string Address2 { get; set; } public string ZipCode { get; set; } public int State_ID { get; set; } } 1. Select an item from either the dropdownlist or the combobox. 2. Click the button. At this point both the dropdownlist and combobox controls would clear themselves. 3. Select an item again from either the dropdownlist or the combobox. 4. Click the button again. At this point only the .NET combobox will clear while the Telerik dropdownlist will retain the displayed item.

Workaround:

add an empty State in the stateslist:

stateslist.Add(new States() {DisplayName = "", ID = 0});
1 comment
ADMIN
Ralitsa
Posted on: 26 Mar 2014 14:30
Resolution:

The Microsoft ComboBox setting the SelectedIndex to “-1” when the set SelectedValue does not represented in DataSource of the control. While RadDropDownList does not change the SelectedIndex to -1 if the SelectedValue does not exist in DataSource of control. We consider that both behavior have their advantages and disadvantages. However, we do not have plans to change our behavior. If more people request it we may review our decision.

In the provided case after the change of the DataSource of the AddressBindingSource the State_ID becomes with value 0(default value for integer types) which is not represented in DataSource of RadDropDownList, which leads to described undesired behavior. 

To achieve the desired behavior you can use the provided workaround.