471,599 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

updating a ListBox's elements

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?
Nov 17 '05 #1
1 2605
"MrNobody" <Mr******@discussions.microsoft.com> wrote in message
news:DE**********************************@microsof t.com...
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
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by James Goodman | last post: by
1 post views Thread by Spock | last post: by
14 posts views Thread by Paul_Madden via DotNetMonster.com | last post: by
3 posts views Thread by Reg Verrin | last post: by
15 posts views Thread by Doogie | last post: by
2 posts views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.