User Control Public Property Problem

Hello,

I'm having trouble with one of my user controls.

I have a public property:

Private mToto as DataRow

Public Property Toto as DataRow
Get
     Return mToto
End Get
Set (ByVal Value as Toto)
     mToto=Value
End Set
End Property

Now the wierd thing is that whenever I try to add this user control to a form, not only does this property appear in the property window but I get an error "Object reference not set to an instance of an object".
Now when I take a look at the Windows Designer Generated Code, I see

Me.MyUserControl.Toto = Nothing

When that thing is removed, it works fine.

Why on earth does he do that   And how can I prevent that 

Thanks for your help.


Answer this question

User Control Public Property Problem

  • faith_a2Z

    GNarl,

    As your property is of type datarow, you probably do not want this to show in the designer.  Try this:


        <Browsable(False), _
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Property Toto as DataRow 
           Get 
               Return mToto 
           End Get 
           Set (ByVal Value as DataRow) 
               mToto=Value 
           End Set 
        End Property 


    Also notice that you have the type Toto in the set, it should be DataRow.

  • User Control Public Property Problem