467,911 Members | 1,430 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,911 developers. It's quick & easy.

ListBox Items not Updating/Refreshing

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!
Nov 16 '05 #1
  • viewed: 8897
Share:
3 Replies
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?

"gdbjohnson-AT-yahoo-dot-ca-nospamplz" <an*******@discussions.microsoft.com>
schrieb im Newsbeitrag news:85****************************@phx.gbl...
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!

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

g

-----Original Message-----
First there are two ListBox objects: One for Windows Form and one for theWeb, which ListBox are you talking about?

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

Are you using A Windows Form ListBox with ListItem?

"gdbjohnson-AT-yahoo-dot-ca-nospamplz" <an*******@discussions.microsoft.com>schrieb im Newsbeitrag news:85cc01c495f1$4df02fe0

$a*******@phx.gbl...
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!

.

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

g

-----Original Message-----
First there are two ListBox objects: One for Windows Form and one for theWeb, which ListBox are you talking about?

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

Are you using A Windows Form ListBox with ListItem?

"gdbjohnson-AT-yahoo-dot-ca-nospamplz" <an*******@discussions.microsoft.com>schrieb im Newsbeitrag news:85cc01c495f1$4df02fe0

$a*******@phx.gbl...
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!

.

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Dave | last post: by
1 post views Thread by Spock | last post: by
1 post views Thread by erin.sebastian | last post: by
7 posts views Thread by samoore33 | last post: by
3 posts views Thread by Reg Verrin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.