tags:

views:

95

answers:

2

I have a .net winforms ListBox and I've added items to it using .Add(). I change one of the objects in the list, such that it's ToString() method now returns a different value, but the display value of the item doesn't update. What do I need to call to tell the ListBox to re-read the ToString values?

+1  A: 

Since you've added the items by hand, you'll need to clear the list box items, and re-add them.

When you add an item with .ToString(), the list box just has a copy of the string itself - it has no way to know that the item has changed, or that it was even based off an item. You'll have to handle this yourself.

Reed Copsey
+1  A: 

If you re-assign the same object reference to the same listbox item, the listbox will refresh its display value. e.g.:

Thingy thing = this.listBox1.Items[0];
thing.DoSomethingThatChangesToStringReturnValue();

this.listBox1.Items[0] = thing;
Nicole Calinoiu