ListBox Items not Updating/Refreshing

G

Guest

I have a ListBox built of a simple custom object for the
ListItems used to be able to hold a Data Value, and a
Display Value, with accessors for each. I have
overridden the ToString method to display the Display
value.

(Two examples that I have seen, including an MS example,
suggest that the DisplayMember and ValueMember properties
of the ListBox can be used in this way, I could not get
it to work using the ListItems.Add method - overriding
toString() seems to be the only way. Setting Datasource
may be a different story.)

When I update the Display value of the underlying object,
the associated ListBox entry does not update, nor have
any of my attempts to refresh the list worked.

Ex:
((CustomObject) lstControl.SelectedItem).Display = "New
Display Value"

The underlying object updates properly. But the ListBox
continues to show "OLD Display Value" in the control!

How do I get it to call the ToString() method again for
that item? Someone has already suggested that I remove
and then re-add the item, but I do not want to do this if
I can avoid it - there must be a way to get the ListBox
to refresh. Help!
 
Z

Zürcher See

First there are two ListBox objects: One for Windows Form and one for the
Web, which ListBox are you talking about?

Web ListBox use the ListItem object and its property .Text to display it
Windows Form ListBox accept all the objects and use the .ToString() method
to display them

Are you using A Windows Form ListBox with ListItem?
 
G

Guest

It's a Windows Form:
This is how I add my DegreeLst object:
lstDegree.Items.Add(new DegreeLst(degreeID,
displaystring));

g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top