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?

2 Answers 2

5

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;
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.