Error lost in databinding

I

Igor Anic

I have a business object which has a property bound to textbox:

txt.DataBindings.Add(new Binding("Text", obj, "MyProp"));

Object property set method for MyProp is something like:

set
{
if (...)
throw(new ApplicationException("error message"));
else
_myProp = value;
}


The problem is that I would like to display that error message to the
user. But it is eaten somewhere in the binding mechanism.
Binding is looking for the Validating event, and when the error occurs
in the property set just cancels validating.
How can I display that error to the user?

Thanks,
Igor.
 
N

Neil Allen

I have a business object which has a property bound to textbox:

txt.DataBindings.Add(new Binding("Text", obj, "MyProp"));

Object property set method for MyProp is something like:

set
{
if (...)
throw(new ApplicationException("error message"));
else
_myProp = value;
}


The problem is that I would like to display that error message to the
user. But it is eaten somewhere in the binding mechanism.
Binding is looking for the Validating event, and when the error occurs
in the property set just cancels validating.
How can I display that error to the user?

Thanks,
Igor.

Dear Igor

You're right - don't throw an exception in a property accessor when
your object is "data bound". Have a look at the IDataErrorInfo
Interface...

Reference...
http://msdn.microsoft.com/library/d...temcomponentmodelidataerrorinfoclasstopic.asp

Example of how to use the interface with your own business objects...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp


We've found the IDataErrorInfo Interface to work well with the
System.Windows.Forms.ErrorProvider and you can supplement it with
events if you want more flexibility.

If you use your business objects in a "middle tier" you can flag
whether you want to throw exceptions.


Hope this helps

Regards


Neil Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top