If you use the BindingSource
component to do data binding, then this will not be too hard. If you are not
using the BindingSource component, then I would highly recommend that you do
because otherwise things are going to be a lot more complicated and you might
have to handle a lot more events.
Here are the two events that you need to be concerned with
(all on the BindingSource component):
·
BindingComplete - This fires when a binding operation is
completed (that is, after it is done trying to push the value into the
property). The event args have a BindingCompleteState property that returns one
of three states: Success (if everything went OK), DataError (if it is able to
push the value into the property but the value failed validation), and
Exception (if an exception was thrown for any reason).
·
DataError - This event will report exceptions that happen during
CurrencyManager events (usually because someone handles an event like
CurrencyManager.CurrentChanged and does something that causes an exception).
Do not confuse the DataError event with the
BindingCompleteState.DataError value in BindingComplete. You might think that
the DataError event will fire when a value fails validation, but this is not
the case.
If an exception occurs in the setter of the property (or
something called by the setter) or if there is an exception thrown by the
reflection code that is trying to call the setter, you might see odd behavior
in your controls, such as your control not letting you change focus to anything
else. If you ever see this behavior and you are not sure why, handle the
BindingSource.BindingComplete event and you will probably find out what is
going on.
It is not a bad idea to handle the BindingComplete and
DataError events just so that you can be aware when these exceptions occur,
even if it is just for debugging purposes. Otherwise, bad things could be
happening and you might not know it.