ComboBox binding to Items Collection

Gary C

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;

}

}

Victor

Thank you for your question. The reason why RadComboBox is not being bound is that it does not have a BindingContext object until it is added to a container and the form on which the container resides is shown. You can force RadComboBox to bind itself when you assign a BindingContext explicitly, for example:

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.