ListBox component and underlying Items objects

G

Guest

Hello,

I've run into a brick wall in working with a standard ListBox. I'm loading
lightweight objects into a ListBox component - call them Elements. The
Element class has an ElementName property and an overridden ToString() method
that displays the ElementName. When I load Elements into my list box Items
collection, the ElementName displays and all is well. My problem occurs
when I change an ElementName property programatically. The underlying
Element does indeed change, but I can't get the text displayed the list box
to reflect it! I can delete and re-add the Element and the change will show
up, but neither ListBox.Update() nor ListBox.Refresh() change it.

I've considered a custom draw method (which I may have to implement anyway).
But is there another way of changing the text I'm overlooking? I'm not
using data binding - can a ListBox programatically bind to its own Items
collection?

Any help appreciated.

Thanks much

Jim Stanley
Media Services, Inc.
 
M

MarkR

It sounds like it's a reference issue, rather than a painting one, but
without your code I can't be sure. Check whether ListBox.AddItems() might
create a copy of your original object, and/or whether you are changing the
ElementName or just a copy of the ElementName.

(e.g. many string functions return a copy of the original string, rather
than changing it in-place; if the ElementName property accessor is returning
a copy of the ElementName, then you may simply be changing it).

Try posting a small code sample.

/m
 
M

Morten Wennevik

Hi Jim,

This issue has been brought up earlier, and I'm afraid I don't know any other way than to reinsert the changed item. It appears that once inserted, there is no way to tell the ListBox that it's own list of strings to be painted is out of date.
 

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