Problem with winforms ComboBox and databinding

Problem with winforms ComboBox and databinding

Old forum URL: forums.lhotka.net/forums/t/5828.aspx


simon_may posted on Wednesday, November 19, 2008

My BOs expose some namevalue lists as  properties that i bind a comboBox dartasource property to, However the act of binding the datasource alters the SelectedValue property which is not desirable. Having traced the databinding process I can see the SelectedValue binding then the DataSource binding which alters the SelectedValue.

Anyone have any ideas as to how I should be doing this properly

Regards

Simon

IanK replied on Wednesday, November 19, 2008

Make sure you are binding the namevalueList to combobox's bindingsource prior to binding to your main business object.'s binding source.

The binding on the combobox will automatically select the first item. The subsequent initialization of binding to your business object should reset it to the value displayed on combo to the property of the BO it is associated with.

simon_may replied on Wednesday, November 19, 2008

I am rapidly coming to the conclusion that that is the root of the problem. The ComboBox's bindings bind the SelectedValue and the Datasource to the BOs bindingsource because if the BO is a child there may well be no instance for the comboBox to bind to (the subsidiary datasource that binds the child collection), and therefore there is  no NameValueList property for me to explicitly bind the ComboBox datasource to. Data binding handles this situation without complaining, and that is why I tried to do it this way. If the order of binding was logical i.e. the datasource then the SelectedValue then there would be no problem.

Am I the only person that wants this sort of  functionality or is my design fundametally wrong

Copyright (c) Marimer LLC