forms designer loads slow with derived control

  • Thread starter Thread starter PGP
  • Start date Start date
P

PGP

I recently derived from a ComboBox to make a countries combo and included it
in couple of forms. The derived combo box loads an xml list of countries and
uses the DataSource and DisplayMember properties to point to the appropriate
node in xml. All this is done in the derived combo's constructor. This
causes forms designer to load slower as it seems to initialize these derived
combos with the country list.
If i did not care about the countries list at design time (I do want to see
the combo box as is though) and did care about the time taken to open forms
in designer, is there anything i could do to make this faster? Should i
wait to load the countries list? if so, when will i do it? Ideally, if i
could turn off the constructor code execution during form design that will
be great.

Priyesh
 
I recently derived from a ComboBox to make a countries combo and included it
in couple of forms. The derived combo box loads an xml list of countries and
uses the DataSource and DisplayMember properties to point to the appropriate
node in xml. All this is done in the derived combo's constructor. This
causes forms designer to load slower as it seems to initialize these derived
combos with the country list.
If i did not care about the countries list at design time (I do want to see
the combo box as is though) and did care about the time taken to open forms
in designer, is there anything i could do to make this faster? Should i
wait to load the countries list? if so, when will i do it? Ideally, if i
could turn off the constructor code execution during form design that will
be great.

You should not do any heavy lifting in the constructor. You should
load database data later... I'm thinking maybe try overriding the
OnCreateControl() method and do it in there, like this:

protected override void OnCreateControl()
{
base.OnCreateControl();
if (!this.DesignMode)
{
... read stuff from database ...
}
}

The DesignMode property _should_ be set properly by then, so the
control should not attempt to load anything when in the designer. In
theory. :-)
 
You should not do any heavy lifting in the constructor. You should
load database data later... I'm thinking maybe try overriding the
OnCreateControl() method and do it in there, like this:

protected override void OnCreateControl()
{
base.OnCreateControl();
if (!this.DesignMode)
{
... read stuff from database ...
}
}

The DesignMode property _should_ be set properly by then, so the
control should not attempt to load anything when in the designer. In
theory. :-)
Bruce,
Thanks! DesignMode - That's exactly what i was looking for. It works!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top