I have a form which has two ComboBoxes. I'd like to use the second (child) ComboBox to display a list of child objects based on user selection of an item from the first.
When the form is instantiated, I databind both controls to private List<Widget>s like so:
private List<ParentWidget> _parentList;
private List<ChildWidget> _childList;
public FormExample()
{
InitializeComponent();
_parentList = GetParentWidgets();
_childList = new List<ChildWidget>();
cmbParent.DisplayMember = "WidgetName";
cmbParent.ValueMember = "ID";
cmbParent.DataSource = _parentList;
cmbChild.DisplayMember = "WidgetName";
cmbChild.ValueMember = "ID";
cmbChild.DataSource = _childList;
}
When the parent selected index is changed, I then populate _childList with the appropriate objects.
The problem is the child ComboBox never shows any of the objects in the collection. It works if I populate the collection with at least one ChildWidget before databinding it, but I'd like it to start empty.
If I understand correctly from another answer, this is failing because the empty list does not contain any properties to bind to. However I am binding to a specific class (Widget) rather than a generic object. Is this not sufficient for the databinding?