Re: Exception in property in Windows Forms DataBinding
From: Piotrek (pasdeSPAMileoudd_at_hotmail.com)
Date: 11/03/04
- Next message: Piotrek: "Binding solution: refresh changes made by code in custom classes"
- Previous message: Piotrek: "Re: Datagrid individual cell colors"
- In reply to: Giles: "Re: Exception in property in Windows Forms DataBinding"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 3 Nov 2004 11:55:16 +0200
Hi Giles
Exceptions that shall occur in your custom class are simply caught inside
the binding mechanism:
you must not raise exception, they will be caught before you try to catch
them (the symptom is that the focus dont move)
1) Do not use exception to handle normal processing (a bad value is to be
considered as a problem you can manage, it is not an error)
2) You can notify very simply your UI if you impement IDataErrorInfo in your
custom class as shown there:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02252003.asp
Nevertheless: Be extra careful in the code you make in your custom class,
usually you put your business code there, imagine if you have an exception
that you don't catch(on price calculation, product validation...), it could
very easely lead to a serious issue...
"Giles" <Giles@discussions.microsoft.com> wrote in message
news:ADD68DD4-F2C9-4A58-B716-B380BD7EF9C0@microsoft.com...
> Hi,
>
> Have you found a solution to this yet?
>
> I am experiencing a similar problem. - Im binding a text box to a custom
> class (that throws exceptions when the value is not correct). if the
value
> is not correct the focus does not move out of the text box. Is there any
way
> to establish that an error has been thrown and indicating this in an
> errorprovider?
>
> cheers,
>
> Giles
>
>
> "Henrik Skak Pedersen" wrote:
>
> > Hi Sijin,
> >
> > Thank you very much for your reply.
> >
> > I am using the same code from both the UI and from code. Should I then
both
> > throw an exception and set the error property?
> >
> > Henrik Skak Pedersen
> >
> > "Sijin Joseph" <sijinNOSPAMdotnet@hotmail.com> wrote in message
> > news:%23IWV1ApqEHA.372@TK2MSFTNGP12.phx.gbl...
> > > Hi Henrik,
> > >
> > > What i meant was that instead of throwng an exception you should set
the
> > > error property in the IDataErrorInfo interface, that ways the UI knows
> > > that there is an error in your object.
> > >
> > > Sijin Joseph
> > > http://www.indiangeek.net
> > > http://weblogs.asp.net/sjoseph
> > >
> > > Henrik Skak Pedersen wrote:
> > > > Hi,
> > > >
> > > > Thank you very much for your answer. I have allready tried that and
I
> > know
> > > > that I have to implement the IDataErrorInfo interface to show errors
in
> > the
> > > > ErrorProvider. But how do I catch exceptions?
> > > >
> > > > Henrik.
> > > >
> > > >
> > > > "Sijin Joseph" <sijinNOSPAMdotnet@hotmail.com> wrote in message
> > > > news:eY829uHqEHA.556@tk2msftngp13.phx.gbl...
> > > >
> > > >>Use the IDataErrorInfo interface in this case,
> > >
> >
>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/
> > html/vbnet02252003.asp
> > > >>
> > > >>this article show how.
> > > >>
> > > >>Sijin Joseph
> > > >>http://www.indiangeek.net
> > > >>http://weblogs.asp.net/sjoseph
> > > >>
> > > >>
> > > >>Henrik Skak Pedersen wrote:
> > > >>
> > > >>>Hi,
> > > >>>
> > > >>>I have a problem with exceptions in data binding.
> > > >>>
> > > >>>I have a normal windows form with 2 fields on which binds to an
Custom
> > > >>>List which inherits from CollectionBase and imlements IBindingList
and
> > > >>>IEditableObject.
> > > >>>
> > > >>>I would like to throw an exception in one of the bound properties
if
> > the
> > > >>>user enters an invalid value. Like this:
> > > >>>
> > > >>>public string Id
> > > >>>{
> > > >>> set
> > > >>> {
> > > >>> if(value == invalidValue)
> > > >>> throw new Exception("Inavlid Field Value");
> > > >>>
> > > >>> this.id = value;
> > > >>> }
> > > >>> get { return this.id; }
> > > >>>}
> > > >>>
> > > >>>The following happens. When the exception is thrown I am not able
to
> > > >>>leave the field (that is ok). But I am not able to see the
exception
> > > >>>anywhere, because it is probably caught by the Binding system.
> > > >>>
> > > >>>I would like to display the exception in a MessageBox or display it
> > using
> > > >>>the ErrorProvider. How is that possible?
> > > >>>
> > > >>>Best regards
> > > >>>
> > > >>>Henrik Skak Pedersen
> > > >
> > > >
> > > >
> >
> >
> >
- Next message: Piotrek: "Binding solution: refresh changes made by code in custom classes"
- Previous message: Piotrek: "Re: Datagrid individual cell colors"
- In reply to: Giles: "Re: Exception in property in Windows Forms DataBinding"
- Messages sorted by: [ date ] [ thread ]