This question is locked. New answers and comments are not allowed.
Hello,
We are upgrading to the latest version of the WinForms components. I see there have been changes to the binding logic. I have a RadComboBox and I'm binding a list to it. If I create the combo dynamically and assign my list to the datasource property the Items collection is not bound (Items.Count = 0) until I assign the combo box to a container.
Is there a way to force this sooner without requiring a parent component? In this case our combo box is in a grid with an image associated with each item in the list so we are doing some initialization and need the items to be there for this.
Thanks,
-Gary
Here is some code to demonstrate the problem:
We are upgrading to the latest version of the WinForms components. I see there have been changes to the binding logic. I have a RadComboBox and I'm binding a list to it. If I create the combo dynamically and assign my list to the datasource property the Items collection is not bound (Items.Count = 0) until I assign the combo box to a container.
Is there a way to force this sooner without requiring a parent component? In this case our combo box is in a grid with an image associated with each item in the list so we are doing some initialization and need the items to be there for this.
Thanks,
-Gary
Here is some code to demonstrate the problem:
| public partial class Form1 : Form |
| { |
| const string DISPLAY_FIELD = "Name"; |
| const string VALUE_FIELD = "ID"; |
| public Form1() |
| { |
| InitializeComponent(); |
| } |
| private void radButton2_Click(object sender, EventArgs e) |
| { |
| List<ComboItems> comboItems = new List<ComboItems>(3); |
| comboItems.Add(new ComboItems("Red", 1)); |
| comboItems.Add(new ComboItems("White", 2)); |
| comboItems.Add(new ComboItems("Blue", 3)); |
| RadComboBox rcb = new RadComboBox(); |
| rcb.DisplayMember = DISPLAY_FIELD; |
| rcb.ValueMember = VALUE_FIELD; |
| rcb.DataSource = comboItems; |
| // rcb.Items.Count == 0 at this point |
| rcb.Parent = this; |
| // now rcb.Items.Count == 3 |
| } |
| } |
| public class ComboItems |
| { |
| public string Name { get; set; } |
| public int ID { get; set; } |
| public ComboItems(string displayMember, int valueMember) |
| { |
| Name = displayMember; |
| ID = valueMember; |
| } |
| } |