好的,下面是解决方案:
我们需要处理bindingSource、currencyManager或bindingBanageRBase类的bindingComplete事件。代码可以如下所示:
/* Note the 4th parameter, if it is not set, the event will not be fired.
It seems like an unexpected behavior, as this parameter is called
formattingEnabled and based on its name it shouldn't affect BindingComplete
event, but it does. */
txtAge.DataBindings.Add("Text", dataSource, "Name", true)
.BindingManagerBase.BindingComplete += BindingManagerBase_BindingComplete;
...
void BindingManagerBase_BindingComplete(
object sender, BindingCompleteEventArgs e)
{
if (e.Exception != null)
{
// this will show message to user, so it won't be silent anymore
MessageBox.Show(e.Exception.Message);
// this will return value in the bound control to a previous correct value
e.Binding.ReadValue();
}
}