Hi there,
I have a class that implements IComponent. When I drop this component from
the toolbox onto the form, I get a null exception while trying to access the
'Site.DesignMode property'. Site object seems to be null.
I believe my error should be pretty obvious (I must be missing something),
but I've tried dozens of code changes to no avail. Can't find a useful
example so I post a code excerpt here:
namespace Spaces
{
[DesignerAttribute(typeof(CustomerList.MyDesigner))]
public class CustomerList : BindingList<Customers>, IComponent
{
private ISite mSite;
public event EventHandler Disposed;
Persister pers;
public CustomerList()
{
if (!this.Site.DesignMode) <== null exception here
{
// This should not run when adding the component to the form:
pers = new Persister(this, GetSchema());
Initialize();
}
}
internal class MyDesigner : System.Windows.Forms.Design.ControlDesigner
{
MyDesigner() { }
public override void Initialize(IComponent component) {
base.Initialize(component); }
}
...more class code
}
}
I appreciate any help.
Regards,
-Benton
Andrew Smith (Infragistics) - 17 Jan 2006 04:36 GMT
The Site is a property of component but it cannot have been set while you
are still processing the constructor. You'll need to perform that check
later or perform that code and then if the Site property gets set, throw
away whatever information is not needed at design time.
> Hi there,
>
[quoted text clipped - 41 lines]
>
> -Benton