Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bound ListBox not updating

Status
Not open for further replies.

BlackburnKL

Programmer
Oct 21, 2002
196
0
0
US
I have a ListBox on a Windows Form which is bound to a property of an object. The object's property is a list of messages, defined as List<string>.

In code I have updated the object and its list of messages, but the list displayed in the ListBox has not changed. I can force the list to update by killing the data binding and setting it up again, but it seems that the whole purpose of binding it in the first place was so that changes would be reflected on screen.

I have traced it through and find that the object has indeed changed and that the ListBox is bound to the object's property. All tests show that they are equal, but the items on their lists are different.

Any ideas?

BlackburnKL
 
If you are binding like

ListBox.DataSource = list;
ListBox.DataBind();

Then yes you need to rebind if the list changes.
 
To clarify, when the object is created, we use the following code:

ListBox.DataBindings.Clear();
ListBox.DataBindings.Add("DataSource", myObject, list);

Do I still need to rebind? And, if so, what does the binding buy me in the first place (other than not having to populate the list in the listbox)?

BlackburnKL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top