NameValueListBase Databinding problem

NameValueListBase Databinding problem

Old forum URL: forums.lhotka.net/forums/t/1546.aspx


Jeroen Sneyers posted on Friday, October 20, 2006

Hi all, I started off with CSLA a couple months ago and I must say, it's awesome. It thought me a lot and still does, so here's a small question.
I have a class 'SalesManList' which inherits from NameValueListBase and contains a static list of Ids and names of salesmen. It's based on the class 'RoleList' from the ProjectTracker example.
In a windows form, I have 2 comboboxes which are bound to this static list.

cmbPartsResponsible.DataSource = SalesManList.GetList();
cmbWorkShopResponsible.DataSource = SalesManList.GetList();
(ValueMember = "Key", DisplayMember = "Value")

My problem is, that when I change the value of one combobox, the other also gets the same value.
E.g. I set combobox cmbPartsResponsible to "John Smith", then the value of cmbWorkShopResponsible also changes "John Smith". This is probably due to the static list in the class 'SalesManList'.
Could anyone tell me what I'm doing wrong here or how I could resolve this issue?

Many thanks, J.

ajj3085 replied on Friday, October 20, 2006

Not sure I understand... is the SalesManList keeping track of the selected value?  It shouldn't be.. another BO should have PartsResponsibleId and WorkshopResponsibleId..

If you do have such a BO, you probably bound the combox boxes to the same property.

HTH
Andy

Brian Criswell replied on Friday, October 20, 2006

I think he has two ComboBoxes bound to the same list.  If you select an item from one list, the same item will be selected in the other list.

  I think in this case you will need to set up two separate BindingSource objects, but you may be able to set them to the same instance of the list.  Otherwise, try to separate instances of the list.

Jeroen Sneyers replied on Friday, October 20, 2006

Indeed Brian, I had to set up two separate BindingSource objects. Thx a lot.

Jeroen Sneyers replied on Friday, October 20, 2006

Thanx for the response.

The SalesManList does not keep track of the SelectedValues. There's a root BO 'Client' which contains the properties PartsResponsibleId and WorkshopResponsibleId, so they keep track of the selectedValue.

In design view I bind clientBindingSource.PartsResponibleId to the SelectedValue of cmbPartsResponsibleId and clientBindingSource.WorkshopResponsibleId to the SelectedValue of cmbWorkshopResponsibleId. In the OnLoad method of the windows form, I populate the comboboxes as following:

cmbPartsResponsibleId.DataSource = SalesManList.GetList();
cmbWorkshopResponsibleId.DataSource = SalesManList.GetList();

J.

Copyright (c) Marimer LLC