error trapping when binding to custom class

G

Guest

I have a custom class object which I'd like bound to text boxes etc on the form. All properties of the class look something like this

<System.ComponentModel.Description("Get/Set value associated with Phone column")>
Public Property Phone() As Strin
Ge
Me.CheckDisposed(
If (m_IsNullPhone = True) The
Throw New System.Data.StrongTypingException("Cannot get value because it is DBNull", Nothing
End I
Return m_Phon
End Ge
Set(ByVal Value As String
Me.CheckDisposed(
m_Phone = valu
m_Changed = Tru
m_IsNullPhone = Fals
End Se
End Propert

Whe I bind this property to a text box I get this error just after the form load
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in system.dl

Additional information: Property accessor 'Phone' on object 'PPSS.Person' threw the following exception:'Cannot get value because it is DBNull

There seams to be no obvious way to intercept this error using the Binding object but can only catch it by using a high level error trap. The dataset object seams to handle this situation without raising an error so i guess there must be a way to do this.

Regard
 
K

Ken Tucker [MVP]

Hi,

Instead of throwing an error if the phone isn't set why dont you make
the user set it when he creates a new one of your custom classes. That way
you dont have to worry about it being null.

Public Sub New(byval Phone as string)
m_phone = phone
End sub

Ken
 
G

Guest

I can't do that.
My values come from the database and all my classes support IsPropertyNull (i.e IsPhoneNull) properties and SetPropertyNull (i.e. SetPhoneNull) methods. Strongly typed datasets seam to handle this nicelly but I just don't see how. I think inspection of MSIL is next (not that I wanted to go there).

Thanks for the effort.
 

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