Hi Mikus,
I've done more research on this issue and found more information to share
with you.
From document of Binding.FormattingEnabled [4]:
Setting this property to true also enables error-handling behavior and
causes the BindingComplete event to be raised. The handler of this event
can take the appropriate action, based on the success, error, or exceptions
in the binding process, by examining the BindingCompleteState property of
the BindingCompleteEventArgs parameter.
So we need to follow Marc's suggestion in his first reply:
private void class1BindingSource_BindingComplete(object sender,
BindingCompleteEventArgs e)
{
if (e.BindingCompleteState == BindingCompleteState.Exception)
{
MessageBox.Show(e.Exception.Message );
}
}
But this need the FormattingEnabled property of the Binding class set to
true. If it's false, the exception will just get consumed by the Binding
class and never has a chance to report back.
However, this requirement conflicts with the other issue you've mentioned
in [1]; which is also reported as a known bug [2]. So my workaround in that
post is not completely working: it will cause this issue you're
experiencing. I must apologize for the confusion I've caused.
So, I think we will just make sure the FormattingEnabled property set to
true as the designer generated code did that for us. We will need find
another workaround to deal with the bug mentioned in [1] and [2].
We can use following workaround instead:
In the business object's PropertyChanged event, we can flip the
FormattingEnabled property of the Binding to make it reflect the changed
property value back to the source:
Class c1 = new Class1();
c1.PropertyChanged += new
PropertyChangedEventHandler(c1_PropertyChanged);
...
void c1_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
foreach (Binding b in textBox1.DataBindings)
{
if (b.IsBinding && b.BindingMemberInfo.BindingMember ==
e.PropertyName)
{
b.FormattingEnabled = !b.FormattingEnabled;
b.FormattingEnabled = !b.FormattingEnabled;
}
}
// you may need to handle other controls' DataBindings too
}
Please let me know what do you think of above workaround. Thanks.
References:
[1] #Control bind to object does not refresh it's display in
dotnet.languages.csharp
http://msdn.microsoft.com/newsgroups...icrosoft.publi
c.dotnet.languages.csharp&tid=31384fbc-a888-4286-b6c9-c3be53e77e5e&m=1&p=1
[2] #Feedback: Current control doesn't refresh values due to
PropertyChanged event
http://connect.microsoft.com/VisualS...k.aspx?Feedbac
kID=115342
[3] #Binding behaviour regarding exceptions in dotnet.languages.csharp
http://msdn.microsoft.com/newsgroups...icrosoft.publi
c.dotnet.languages.csharp&mid=72e21545-078c-4676-96aa-46c481827590&sloc=en-u
s&m=1
[4] #Binding.FormattingEnabled Property (System.Windows.Forms)
http://msdn2.microsoft.com/en-us/lib...binding.format
tingenabled.aspx
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.