Hi there,
in our application we have several combos for displaying things like payment method, tax class, credit card type etc. for an Order. In the Order those items are stored with their id (PaymentMethodId, TaxClassId, CreditCardTypeId) as integer values. Some of those combos are UltraCombo, other UltraComboEditor classes. I've set their DropDownStyle to DropDown, the AutoCompleteMode to SuggestAppend. The list of items, the combos are displaying, are fetched from a list of our business objects using MS BindingSource, I've set the DataBindings properties Value, DisplayMember and ValueMember appropriately and that works at it should be.
To prevent entering values that are not in the list of items I've attached an event handler to the ItemNotInList event. In that handler I proceed as you suggested in one of your examples which also works fine.
Now with one of the several UltraComboEditor objects used I've a small problem. I've also subscribed for BindingComplete event on the Order object to check if an error during binding occurs. In this one combo as soon as I enter one single character which never could lead to a valid item of the list the BindingComplete event is fired with a System.FormatException saying that the input string was not in correct format. I can of course suppress this exception but I would like to understand how this could be. From my understanding data is only written back to the Order business object when the UltraComboEditor looses focus which is not the case. I also don't understand why this event gets fired before the ItemIsNotInList event so that I can appropriately react on that. I even registered a Click event on that combo to check before if the item is in the list but also that is not called before the BindingComplete event.
It's strange that I experience this problem just with one UltraComboEditor while other's are working fine although they are all working the same way on the same Order Business Object? When I enter an illegal value in the other combo boxes the event handler for ItemNotInList event gets called and I can react on that appropriately.
Any ideas?
Kind regards,Wolfgang
Hi Mike,
thanks for your instant reply, I really appreciate that!
With the inputs from your posting I did several tests this morning and also found out what was the problem thus could solve it. I want to share that information with you.
My assumption was correct, the value is written back to the underlying business object only when the control (the combo in that case) looses the focus. I've verified that behavior by setting a breakpoint onto the property in the business object and the debugger stopped only there if I changed the focus to another control. I've also set a breakpoint onto the event handler for value changed and that has been hit every time I entered a character. What you've mentioned with that the BindingManager looks for a Changed event with the same name as the property (e.g. property OrderId -> OrderIdChanged) is for the case that the property gets changed in the Business Object from somewhere else so that the combo gets updated. I've also verified that by simply putting a dummy button onto the GUI which does nothing else in the Click event handler than setting the property to another id. The combo then immediately shows the appropriate name which is associated with that Id so that is a correct behavior as I would expect it.
During the tests I've found out what the problem was. I want to recalculate the order as soon as the combo has a new value selected without requiring the user to move away the focus to another control since that is not very intuitive. Since the value is not updated in the underlying Business Object until the combo looses the focus I've forced that by applying following code: comboEditor.DataBindings[0].WriteValue(); My mistake was that I was doing that in the event handler for ValueChanged on the combo so it has been called every time I inserted a character. Now I've moved the code onto event handler for SelectionChanged and now it's working as it should.
If you've some complains or improvement thoughts on that pls let me know.
Regards, Wolfgang
Hi Wolfgang,
qbupoew said:From my understanding data is only written back to the Order business object when the UltraComboEditor looses focus which is not the case.
I'm not entirely sure that this is a correct assumption. I'm pretty sure there are several options for this. But my guess is that if you are binding the Value property of the control, then the underlying data object will be updated any time the control fires the ValueChanged event. That's how the BindingManager works - it looks for an event with the same name as the property and listens to it.
Assuming the combo had a valid value in it and was not null, then typing an invalid character could change the Value to null, which would fire ValueChanged which might trigger an exception.
I could be wrong about all of this, of course. It's very tough to say with so little information. It might help if you could post the call stack of the exception. You seem to be under the impression that the exception is coming from the data source, but that exception message looks like something that is coming from the combo to me, and in fact, it looks like a FirstChanceException that you would not normally see unless you have set the IDE to break on all run-time exceptions - even ones that are already handled.