Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Wanna-Be C# Superstar
Posted
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.
Posted
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.
Wanna-Be C# Superstar
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...