updating a ListBox's elements

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I'm doing something where I add custom objects to a ListBox which have
aToString() method overriden so it displays what I want. When adding
instances of these custom objects to the ListBox I also put the same
references in a Hashtable so my program can obtain and modify these objects
without iterating through entire ListBox looking for what I want.

The problem is though, when I update these objects the changes are not being
reflected in the ListBox (The ToString method should be returning something
else but it isn't). There can only be two reasons for this:

1. The ListBox creates it's own copy of whatever object you put into it's
Items collection (This would be really stupid if it does!)

2. More likely, I just don't know how to update the ListBox so it repaints
itself... I tried claling the Refresh() method but tht's not doing it. What
method could I use?
 
MrNobody said:
Hi, I'm doing something where I add custom objects to a ListBox which have
aToString() method overriden so it displays what I want. When adding
instances of these custom objects to the ListBox I also put the same
references in a Hashtable so my program can obtain and modify these
objects
without iterating through entire ListBox looking for what I want.

The problem is though, when I update these objects the changes are not
being
reflected in the ListBox (The ToString method should be returning
something
else but it isn't). There can only be two reasons for this:

1. The ListBox creates it's own copy of whatever object you put into it's
Items collection (This would be really stupid if it does!)

2. More likely, I just don't know how to update the ListBox so it repaints
itself... I tried claling the Refresh() method but tht's not doing it.
What
method could I use?

You might try the listBox.Update method. That will cause the ListBox to be
repainted.

The other problem, and I don't think this is the case, could be that the
ListBox Items collection has its own ToString method that is overriding you
ToString method.

carl
 
Back
Top