Control Initilization Problem

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Hi

I have a custom combobox that adds a few default values within the New
constructor. The combobox is set to dropdown list so only these values
are available at runtime.

The problem i am having is that when the combobox is added to a form,
the Initilization sub of the form adds these values in as an AddRange
for the combo box, therefore dumplicating the items in the box when
the app is run.

Does anyone know how to stop the form adding the items to the
initilization? I am having to delete the problem line before running
each time which is a little bit of a pain.

Thanks

Tom
 
* Tom said:
I have a custom combobox that adds a few default values within the New
constructor. The combobox is set to dropdown list so only these values
are available at runtime.

The problem i am having is that when the combobox is added to a form,
the Initilization sub of the form adds these values in as an AddRange
for the combo box, therefore dumplicating the items in the box when
the app is run.

Does anyone know how to stop the form adding the items to the
initilization? I am having to delete the problem line before running
each time which is a little bit of a pain.

I am not sure if I understand your problem, but is there any reason why
you don't clear the 'Items' before adding new items?
 
I am not sure if I understand your problem, but is there any reason why
you don't clear the 'Items' before adding new items?

Yea, i understand where you are comming from, and this was my original
consideration, however the combobox is a little more complicated...

The combo in question inherits off another combobox that inherits from
the base class. This chap in the middle adds a few items based on
properties, if the problem combo box clears the items first, these
items (which the third generation combobox knows nothing about) will
also be lost...

I was kind of assuming there would be some sort of attribute i could
flag the property with but as yet i cannot find one.

Thanks

Tom
 
I am not sure if you need this:

<System.ComponentModel.ReadOnly(True),
System.ComponentModel.Browsable(False)> _
Public Property ......
 
If not me.DesignMode
... add items
end if

I have tried this, but it did not make any difference. My testing
found that once a control is built and used in another project it is
no longer in design mode.

Cheers

Tom
 
<System.ComponentModel.ReadOnly(True),
System.ComponentModel.Browsable(False)> _
Public Property ......

Makes sense, but on what property? The items are added in the
constructor and the Items property is hidden in the base class.

Cheers

Tom
 
use it on all properties that you don't want to be automatically
initialized neither set using the property window.
 
Back
Top