UserControl Static ComboBox

M

Mark Jerde

I'm not finding help in Google. VS .NET 2003.

I have a user control with a ComboBox. At runtime the ComboBox gets loaded
with a long list of strings. Since I have up to 40 controls on a form I'm
trying to figure out a way for all 40 combobox controls to share the same
list of items.

The ComboBox.Items property is read only so setting all 40 to the same
ObjectCollection won't work.

On a whim I made the combobox static in the UC:
private static System.Windows.Forms.ComboBox cboFields;

This "works" from a data standpoint, as Items.innerlist is the same (and
correct) in all 40 UCs after initializing the first one. But it doesn't
work from the UI standpoint. The ComboBox control doesn't like being shared
across multiple UCs.

Suggestions? Or is there no alternative to haviing the same Items in all 40
instances?

Thanks.

-- Mark
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

Create a string array with your 40 entries and store that where all 40
comboboxes can access it.

Then, set the DataSource property on each combobox to that array.

Hope this helps.
 
M

Mark Jerde

Nicholas -- Thanks, that works great.

-- Mark

Nicholas Paldino said:
Mark,

Create a string array with your 40 entries and store that where all 40
comboboxes can access it.

Then, set the DataSource property on each combobox to that array.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark Jerde said:
I'm not finding help in Google. VS .NET 2003.

I have a user control with a ComboBox. At runtime the ComboBox gets
loaded with a long list of strings. Since I have up to 40 controls on a
form I'm trying to figure out a way for all 40 combobox controls to share
the same list of items.

The ComboBox.Items property is read only so setting all 40 to the same
ObjectCollection won't work.

On a whim I made the combobox static in the UC:
private static System.Windows.Forms.ComboBox cboFields;

This "works" from a data standpoint, as Items.innerlist is the same (and
correct) in all 40 UCs after initializing the first one. But it doesn't
work from the UI standpoint. The ComboBox control doesn't like being
shared across multiple UCs.

Suggestions? Or is there no alternative to haviing the same Items in all
40 instances?

Thanks.

-- Mark
 

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