View Single Post
 
Old 08-04-2017, 09:53 PM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default strange behavior of a inherited class

I'm trying to make a new tool using a class
and inheriting a combobox.

I was having issues with my combobox adding
items twice when clearly, in the code, it's only
being added one time.

All i did was create the class, then i inherited the
combobox. Then i created a public sub new()
and put my code in there to add items to the
Inherited combobox. Me.items.add. I assume
that using ME is correct since i get no errors.
Still though, no matter what i do, items get
added twice to the combobox.

Still using the sub new sub, i commented out all my
code and replaced that with a msgbox. What i found
out is that sub new gets called on three times. It gets
called when the control is placed on the form. It gets
called again when the form loads and again when the
form closes. I thought that sub new only got called
once, when the control is placed on the form.

Am i going about creating a new tool/control the
wrong way? Should i be using a user control to
do this with?

Either way, i'd still like to know why sub new gets called
three times, if anyones knows the answer that is.
Reply With Quote