Home All Groups Group Topic Archive Search About

Form crashes in designer

Author
31 Mar 2006 2:31 PM
FaensenD
I have a sub-class of UserControl that populates a TreeView from a
database. This is done in the constructor. I use

if (this.DesignMode)
     return;


to avoid reading from the database in design mode since the connection
information is not available at this time. This works fine when
designing the UserControl.

However, when I add the UserControl to a Form I get the infamous error:

"One or more errors encountered while loading the designer. The errors
are listed below. Some errors can be fixed by rebuilding your project,
while others may require code changes."

It seems that InDesignMode is only set to true when the UserControl
itself is opened in the designer.

What I tried is to wrap the code that reads from the database in a
try-catch block and ignore any Exception thrown. I do not understand
why the Exception that is thrown within the try-block is not caught.
Does anyone have a suggestion how to handle this.

Daniel

AddThis Social Bookmark Button