Preload combo with items

L

Lee

Hi,

I am wondering whether it is easily achievable to create a custom combo
box control which contains certain items preloaded.

Basically I have a form which will contains several combos, each of
which will contain the same items. Rather then iterating through each
combo as part of the form load I wanted the control to automatically
contain the items.

I tried creating a custom control and adding the code below to either
the constructor or the OnCreateEvent but this resulted in the combo
containing two instances of 'item1' and two of 'item2', because they
were added at design time and run-time.

this.Items.Add("Item1");
this.Items.Add("Item2");

Any assistance would be appreciated.

Lee
 
G

Guest

You can check DesignMode and then create them or not based on when you decide
to create them
 
J

Jay Riggs

Lee said:
Hi,

I am wondering whether it is easily achievable to create a custom combo
box control which contains certain items preloaded.

Basically I have a form which will contains several combos, each of
which will contain the same items. Rather then iterating through each
combo as part of the form load I wanted the control to automatically
contain the items.

I tried creating a custom control and adding the code below to either
the constructor or the OnCreateEvent but this resulted in the combo
containing two instances of 'item1' and two of 'item2', because they
were added at design time and run-time.

this.Items.Add("Item1");
this.Items.Add("Item2");

Any assistance would be appreciated.

Lee

Lee,

Why not use the standard ComboBox control and use the control's Items
property in the form designer?

Am I missing something here?

HTH
-Jay
 
L

Lee

Sorry,

You are right, I'm being an arse.

Lee


Jay said:
Lee,

Why not use the standard ComboBox control and use the control's Items
property in the form designer?

Am I missing something here?

HTH
-Jay
 

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