Thsi isnt working: If Me.DesignMode = True Then Return

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a user control (uc2)which lives on another user control (uc1) on a
form (a nested user control). When I open the form in design view the the
load even fires in uc2 so the first line of code in the in its load event
is:

If Me.DesignMode = True Then Return

However, it doesnt work and code is still executing after this line. The
last line of code in the load event calls a private method which loads data
into a grid. This is the only place this private method gets called and
every time I open the form in design view I get a series of error beeps and
then I see data has loaded into the grid.

Any good advise on how to stop code from executing in design view?

Thanks.
 
The behaviour you're seeing is because the top level control (your form) and
the controls on it are in design mode, the other user control (uc2) is just
part of the implementation of the designing user control (uc1). Notice how
you can't select uc2 when you're designing the form?

In uc2, you can check the Parent.DesignMode (it's protected, you'll need to
add a property to expose it). We have an interface which all our controls
implement to allow controls to check their parent's DesignMode
polymorphically.

If you wanted to get it going quickly, you can also use the value of
Application.ExecutablePath.ToLower().IndexOf("devenv.exe") > -1. You might
want to cache this value, it may have an impact on performance if it's called
frequently.

Hope this helps.

Regards,
Matt Garven
 
Back
Top