I'm trying to implement this pattern in my WinForms application (I don't like it, but it was required by the customer):
- I edit the properties of an object in a DetailsControl (UserControl developed by us), and when the user tries to leave the control, then it's validated and saved
- If it's not valid, or an error occurs during save, then the control must not be left (it's in a List/Detail section)
My idea was this:
- on Validating, I check if my object is fine, otherwise I cancel the event
- on Validated, I save my object, and if an error occurs, I cancel the event
Unfortunately, Validated is not cancelable, and Leave is fired before Validating/Validated. Is there a cancelable event after Validated, that would prevent losing the focus?
If not, I will move all my logic inside Validating, but I would like to keep the formal validation separated from the save errors.