views:

79

answers:

1

Hi, have a really annoying time developing some code for a set of UserControls that utilize fairly rudimentary inheritance. Basically, they are three different Detail Views which all inherit from a single Base Class which in turn Implements a Single Interface.

Interface IBaseDetailView

Class BaseDetailView : Implements IBaseDetailView

Class DetailView1 : Inherits BaseDetailView Class DetailView2 : Inherits BaseDetailView Class DetailView3 : Inherits BaseDetailView

Then I have a Composite UserControl That adds the individual DetailViews 1-3 on a tab on the TabControl.

Pretty Simple stuff. Everything compiles fine, All the UserControls are available in the toolbox and can be dragged and dropped onto any form. But there is one problem...

They initially display and what not, but after compiling the form errors out with the infamous "Instance of object not set to reference" error.

Now, for a bit more info... If I comment out the Form_Load events in each of the DetailView concrete/derived classes this error goes away and the form can be viewed in design mode. The Form_Load events have ado.net calls to a sql server which seem to trigger the errors.

With the Form_Load events in tact I don't receive any errors upon compilation and I can run the applications without a problem while in debug or release mode. I just can't view any forms with the UserControls in DesignMode.

I have added the If Me.DesignMode Then Return to the Form_Load events but it didn't work. I think VS2008 is actually trying to run the code in the UserControls... I googled this but I have not found a solution. Any help is MUCH appreciated!

A: 

Put a null check in around properties/fields in the Form_Load method. We had similar issues as the designer seems to use FormLoad at design time, not what you would expect.

There is also a DesignMode property that you could use.

I hope this helps.

Burt
Thanks Burt! I did check for the designmode property on the control(s) but it would register as false for some wacky reason... I will try using the null checks...
bbqchickenrobot