Hi,
I am trying to implement the following: Two combo boxes on a Winforms form, the first has a list of parent categories, the second is children of the parent, the child list changes contents depending on the selection in the parent.
I'm trying to do this properly using databinding but I'm finding a strange quirk with the ComboBox control.
I set the datasource of the parent manually:
cboParent.DataSource = ParentDataSource
where ParentDataSource is IList<ParentDTO>
.
I can then bind the seletedItem to the DTO thus:
cboParent.DataBindings.Add(new Binding("SelectedItem", bindingSource, "Parent", true, DataSourceUpdateMode.OnPropertyChanged));
binding to Parent
a ParentDTO
object on my overarching DTO.
All pretty standard so far. This works and writes back the change to my DTO object as soon as I select anything new in the list, great!
I then bind the child combo box datasource to a list in the overarching DTO:
cboChild.DataBindings.Add(new Binding("DataSource", bindingSource, "Children", true, DataSourceUpdateMode.OnPropertyChanged));
where Children is an IList<ChildDTO>
on the overarching DTO.
This also works fine and as soon as I change the parent selection the presenter changes the list Children
on the DTO and the values shown in cboChildren changes, fantastic I hear you cry (and I did myself)!
Unfortunately it seems that if you're using databinding to set the datasource on a ComboBox the SelectedItemChanged, SelectedIndexChanged and SelectedValueChanged events don't fire at all, ever! This means that OnProperyChanged databinding won't work for the second combobox. OnValidation does work but it seems a little odd to me and I was wondering if anyone had encountered this before and if they'd worked out how to make it work?
Thanks in advance
Stu