Passing value to windows form user control

  • Thread starter Thread starter Paul McKenna
  • Start date Start date
P

Paul McKenna

Hello

I have a custom user control which I have developed. This user control needs
to have one property value passed to it from the parent form. I tried using
the constructor to do this, the user control builds fine. But if I try to
add it to the form using VS.NET I get a NullReferenceException message and
am unable to proceed. Further, VS.NET does not tell me where exactly the
null reference exception is occuring.

Can someone please help me?

Thank You
 
Hi Paul,


When you cannot see where the error is throwed.

Why are you not debugging it?

(And than remove the parts in your designer where it is told that it should
skip the debugger)

Cor
 
* "Paul McKenna said:
I have a custom user control which I have developed. This user control needs
to have one property value passed to it from the parent form. I tried using
the constructor to do this, the user control builds fine. But if I try to
add it to the form using VS.NET I get a NullReferenceException message and
am unable to proceed. Further, VS.NET does not tell me where exactly the
null reference exception is occuring.

The designer will always call the parameterless ctor, so you will have
to provide such a constructor that doesn't expect any parameters.
 
Thanks I made a work-around. I set the value of the property from the parent
form after initializing the control. The reason I was getting the
nullreference exception was because VS.NEt would overwrite my call to the
custom constructor with a call to the default constructor. This would
nullify my property thus resulting in a runtime error.

Thanks again for your help
 
Back
Top