By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,187 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,187 IT Pros & Developers. It's quick & easy.

Preload combo with items

P: n/a
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

Nov 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You can check DesignMode and then create them or not based on when you decide
to create them

"Lee" wrote:
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

Nov 13 '06 #2

P: n/a
Lee wrote:
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

Nov 13 '06 #3

P: n/a
Lee
Sorry,

You are right, I'm being an arse.

Lee
Jay Riggs wrote:
Lee wrote:
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
Nov 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.