|
-
April 24th, 2008, 01:49 PM
#1
.NET DataBinding oddity
So I'm playing with a screen in our system. On the screen are a few comboboxes that we have databound to a list of stuff from a cache. Dictionary type stuff that we don't have to go to the database for everytime we need the list. Also, two of the comboboxes use the same list as it's datasource. No big deal right?
Well, whenever I set the list explicitly to ComboBox.DataSource, changing the value in one combobox changes the other one too. Before you say it, I've checked a thousand times and the SelectedItem of the binding are set to the two different properties on my business object. The DisplayMember and ValueMember are also set correctly. The selected values of the two comboboxes are getting set in the BO correctly, but they aren't being displayed at all. And, like I said, changing the value in one combobox changes the other.
So, as a test I set the collection into a BindingSource then set the BindingSource as the ComboBox.DataSource. One separate BindingSource for each combobox:
Code:
BindingSource tempBS1 = new BindingSource();
tempBS1.DataSource = Cache.Officers;
cboCollectionOfficer.DataSource = tempBS1;
BindingSource tempBS2 = new BindingSource();
tempBS2.DataSource = Cache.Officers;
cboGradeOfficer.DataSource = tempBS2;
When done this way, the comboboxes behave correctly. They each have their own separate values and they display and save correctly.
Can anyone out there smarter and better than me at databinding tell me why this is? It just doesn't make sense to me changing one combobox would change the other, because all they share is the collection of values to populate in the combobox itself, not the property on the business object where the value comes from. I'm pretty boggled over here!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|