Control Initilization Problem

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
 
H

Herfried K. Wagner [MVP]

* 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?
 
T

Tom

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
 
J

John Smith

I am not sure if you need this:

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

Tom

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
 
T

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
 
J

John Smith

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

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

Top