UserControl Static ComboBox

  • Thread starter Thread starter Mark Jerde
  • Start date Start date
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
 
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 -- 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
 
Back
Top