COmboBox bound by custom collection mayhem

VBAHole22

Contributor
Joined
Oct 21, 2003
Messages
432
Location
VA
Try this out at home:

Create a class with a property that is a collection like List<Crap>.
Then in a win form throw in like 10 comboboxes.
When the form loads create an instance of your class(put some stuff in the collection)
Set each combo's data source to the collection
Change any combo box and they ALL CHANGE.

I don't understand. I want to load each combo with a datasource but after that I want them to act independently of one another. Creating new instances of the collection doesn't solve this. Only creating a new instance of your class will make the combos act on their own.

What am i missing here?
 
All the combo boxes are pointing to the same list which means they are all operating on the same chunk of memory. If you want them to act independently, you'll need to make a copy of the list for each ComboBox.
 
I sort of understand why that is happening but the solution I have is to go and create a new object for each combobox and that seems really wasteful. If there was a way I could copy the initial list and have it 'untie' itself that would work best but I don't know how to implement that.
 
If you're using 2005, I believe you can set up multiple BindingSources' for your one collection and each will keep track of the the same list with different currency managers. Then you would bind the different BindingSources to the different Comboboxes.

I know this works with datasets, but I just haven't tested this out with collections.

If you're not using 2005, sorry I think you have to deal with currency managers and that was annoying.
 
Back
Top