473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
3 9404
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1675
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
7
4518
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
1
3033
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
1
2523
by: erin.sebastian | last post by:
Hello Everyone, I have created a small application in vb.net to maintain items in a database the problem i am having is that once i delete/add/edit an individual item the changes don't reflect in...
7
1896
by: samoore33 | last post by:
I am trying to dynamically add items to a listbox or combobox. The items add to either, but when I look through those items, there is nothing there. If I choose an item, it shows up. Not sure...
6
3945
by: Zytan | last post by:
In win32 there was a way to 'turn off' a listbox from updating until you were done adding elements. Is there a way to do this in .NET? Zytan
1
4009
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
1
2488
by: sweetiecakes | last post by:
Hi I have a ListBox which is binded to a dataSet. When I need to refresh this dataSet, it works, but the old entries don't get removed from the listbox. Items.Clear() doesn't work when a...
3
2725
by: Reg Verrin | last post by:
I have a program that displays constantly changing prices which it sources from the web once per second. The prices are displayed on a Listbox (not the best choice but there are good reasons for...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.