views:

363

answers:

2

I thought this was a simple problem, but I can't find any information on the web. I'm binding a ListBox to a List using BindingSource like so:

List<Customer> customers = MyMethodReturningList();

BindingSource customersBindingSource = new BindingSource();
customersBindingSource.DataSource = customers;

customersListBox.DataSource = customersBindingSource;

Now, when I add or delete from customers list, my ListBox gets updated (even without using ResetBindings on BindingSource), but if I change any of the customer objects in the list, it does not. Calling ResetBindings has no effect. I even implemented my own BindingList, but the behaviour hasn't changed.
The Customer class uses properties for accessing and modification of data. Its ToString() content is displayed in the list.

I'm using C# in .Net 2.0.

Any ideas?

Thanks

A: 

What if you use customersListBox.DataBind()?

willvv
Sorry for the late reply, I had to move on and do it another way. I'm now experimenting at home and I don't have the DataBind() method available for a listBox. Am I missing something here?
orastem
+1  A: 

OK, here's a dirty fix: wenever you need to refresh the box contents set datasource = null, then rebind it.

the reason it doesn't update is because the objects in the list haven't changed and it only checks the refrences of the object rather than their contents.

Michael
Yeah, I think that's what I did in the end (I haven't got the code right now), but as you said, it's dirty.
orastem