Hi!
I'm using an UltraComboEditor that uses Data Binding to get an Id out of an underlying business object which is used to select appropriate item from the items list. If another item is selected in the combo the Id is changed in the business object via the data binding which is fine.
I handle the ValueChanged event of the UltraComboEditor since I have to update another property 'Name' on same business object. This business object implements the INotifyPropertyChanged interface i.e. when 'Name' is set event OnPropertyChanged("Name") is fired causing data binding to fetch all visible properties again. This causes also the UltraComboEditor to display the item associated with the Id from the business object which is the original one thus the selection can never be changed.
I found a solution which works but my feeling is that it is more a workaround. In the ValueChanged event handler of the UltraComboEditor I explicitely set the 'Id' before setting 'Name' I. What I don't like on this solution is that 'Id' is updated again through the data binding.
Comments are welcome, Wolfgang
Hi Mike,
thanks for your instant reply and sorry for writing my entry that unclear. I'll use your example with the U.S. states to illustrate my problem little better.
Let's say that I've a class U.S. State that contains following properties:
I've another class that represents some kind of address having following properties:
I'm doing the databinding to the UltraComboEditor so that the DataSource will be a list of U.S. State objects. The DisplayMember of the UltraComboEditor is set to Name, the ValueMember to StateId. The Value of the DataBindings will be set to StateId of the address binding source.
This works fine and every time I select a different state Name in the combo editor data binding mechanism takes care that the appropriate StateId will be set in the address object.
I also want to set the Capital in the address object whenever a new state is selected so I subscribed for the ValueChanged event of UltraComboEditor, get the ListObject of selected item in the combo which is in fact the selected U.S. State object, fetch the Capital property from it and set the Capital property in the Address object. Now the address object fires OnPropertyChanged("Capital") causing the StateId of the address object to be fetched again to select the U.S. state associated with that StateId so the State in the Combo cannot be changed since it always has the StateId from the Address object.
I've overcome that problem by explicitely setting the StateId property in Address object in the event handler for ValueChanged before setting property Capital and that works fine but I annul the data binding mechanism and that's what I don't like.
Alternativelly instead of subscribing for the ValueChanged event of the UltraComboEditor I could subscribe for the StateIdChanged event from the Address object . This event will be fired when the StateId is updated i.e. when UltraComboEditor looses the focus. Since I'm displaying Capital in a text box I want to see the capital of the newly selected state immediately in the text box, not to have to change the focus to another control. That is imho not quite intuitive from the user's perspective.
Hope that makes it much more clearer.
Kind regards, Wolfgang
Hi Wolfgang,
It's a little hard to understand what's going on here. But it sounds to me like you are binding the list and the Value property of the Combo to the same table. This is logically contradictory and you should not do that.
A ComboBox control is unusual in that it can be bound two ways. You can bind the list and you can also bind the Value. Typically, you would bind to list to a list of options. For example, a list of U.S. States. And then you would bind the Value to a state field in a table of addresses.
If you bound the value to the same list of states that the list is displaying, then selecting an item from the combo would be changing the values on the list. In other words, if you selected New York, and then selected California, you would be changing the New York item on the list to now be California and you end up with 2 California's and no New York.
Maybe I am misunderstanding what you are doing, though.