开发者

Visual Studio 2008 IDE errors with Inherited UserControls

开发者 https://www.devze.com 2022-12-15 17:50 出处:网络
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

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 a开发者_JAVA技巧re 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号