Updating a value based on bound values during focus events in winforms
I have a WinForms form bound to a LLBLGen entity (although I believe this problem to not be specific to this binding source, I mention it just in case). My goal seems pretty simple: update another field on the form based on a calculation for the other fields.
My problem is that I want to reuse the same business logic that is used elsewhere on the form to do this computation and thus I am passing the bound entity to the business logic layer so it can be processed.
What I find strange is that I can't find a place in the focus chain (see: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.enter.aspx ) where I can use the bound entity in an updated form. The calculation is performed fine, but with the pre-update values.
I have worked around this in the past by grabbing values from .text, validating them as usable and going from there. I have also worked around it with "update" buttons: the click event can access the updated value, even if I was clicking immedi开发者_如何学Goately from editing a value.
Still, it seems like I'm missing something obvious: somewhere in the event chain the bound value should be updated and I should be able to run my calculation there.
My core question: what event should I be using to get access to the updated bound element in WinForms?
Considering that my concern was with getting at the bound data changes, I stopped calculating on UI events and switched to listening to the PropertyChanged() event on the entity in question. This bypassed the problem and is working great... and is probably what I should have been doing in the first place.)
I will leave this as unanswered for now; perhaps someone still has an answer for the base question in terms of the focus event chain. I haven't tested this solution with other binding sources, but as INotifyPropertyChanged is the foundation of databinding I suspect the technique will work with other data sources.
精彩评论