creating an inherited treeview, but InitializeComponent is not called?!?

  • Thread starter Thread starter Kevin
  • Start date Start date
K

Kevin

If someone could try this little test I would be most greatful:

In a project, create a new class.
Make this class inherit from TreeView
Switch to designer mode and drop a ContextMenuStrip onto it.
Switch back to code mode and it will have created the variable for
ContextMenuStrip as you would expect, along with "Private Sub
InitializeComponent" for all the initialization stuff.

Now the problem is that normally the InitializeComponent sub is called
from the New sub of the class. However, in this case there is no New
sub because the designer hasn't created one, which means the
initialization code is never called unless you manually add one.

Is this just me being crazy, or is this a bug?

Thanks in advance
Kevin
 
Just call InitializeComponent from the constructor of your class. Because
you didn't create this class using a designer, it didn't automatically
generate the code to call InitializeComponent in the constructor.

- Andrew
 
Hi Andrew,
Yes, thats what I have done, but I just would have thought that the
IDE would have been clever enough to work out that the
InitializeComponent is never called, and thus create a 'new sub'.
Thanks for you help
Kevin
 
Back
Top