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! | | | | re: ListBox Items not Updating/Refreshing
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" <anonymous@discussions.microsoft.com>
schrieb im Newsbeitrag news:85cc01c495f1$4df02fe0$a601280a@phx.gbl...[color=blue]
> 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![/color] | | | | re: ListBox Items not Updating/Refreshing
It's a Windows Form:
This is how I add my DegreeLst object:
lstDegree.Items.Add(new DegreeLst(degreeID,
displaystring));
g
[color=blue]
>-----Original Message-----
>First there are two ListBox objects: One for Windows[/color]
Form and one for the[color=blue]
>Web, which ListBox are you talking about?
>
>Web ListBox use the ListItem object and its[/color]
property .Text to display it[color=blue]
>Windows Form ListBox accept all the objects and use[/color]
the .ToString() method[color=blue]
>to display them
>
>Are you using A Windows Form ListBox with ListItem?
>
>"gdbjohnson-AT-yahoo-dot-ca-nospamplz"[/color]
<anonymous@discussions.microsoft.com>[color=blue]
>schrieb im Newsbeitrag news:85cc01c495f1$4df02fe0[/color]
$a601280a@phx.gbl...[color=blue][color=green]
>> I have a ListBox built of a simple custom object for[/color][/color]
the[color=blue][color=green]
>> 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[/color][/color]
example,[color=blue][color=green]
>> suggest that the DisplayMember and ValueMember[/color][/color]
properties[color=blue][color=green]
>> 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[/color][/color]
Datasource[color=blue][color=green]
>> may be a different story.)
>>
>> When I update the Display value of the underlying[/color][/color]
object,[color=blue][color=green]
>> 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[/color][/color]
ListBox[color=blue][color=green]
>> 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[/color][/color]
if[color=blue][color=green]
>> I can avoid it - there must be a way to get the ListBox
>> to refresh. Help![/color]
>
>
>.
>[/color] | | | | re: ListBox Items not Updating/Refreshing
It's a Windows Form:
This is how I add my DegreeLst object:
lstDegree.Items.Add(new DegreeLst(degreeID,
displaystring));
g
[color=blue]
>-----Original Message-----
>First there are two ListBox objects: One for Windows[/color]
Form and one for the[color=blue]
>Web, which ListBox are you talking about?
>
>Web ListBox use the ListItem object and its[/color]
property .Text to display it[color=blue]
>Windows Form ListBox accept all the objects and use[/color]
the .ToString() method[color=blue]
>to display them
>
>Are you using A Windows Form ListBox with ListItem?
>
>"gdbjohnson-AT-yahoo-dot-ca-nospamplz"[/color]
<anonymous@discussions.microsoft.com>[color=blue]
>schrieb im Newsbeitrag news:85cc01c495f1$4df02fe0[/color]
$a601280a@phx.gbl...[color=blue][color=green]
>> I have a ListBox built of a simple custom object for[/color][/color]
the[color=blue][color=green]
>> 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[/color][/color]
example,[color=blue][color=green]
>> suggest that the DisplayMember and ValueMember[/color][/color]
properties[color=blue][color=green]
>> 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[/color][/color]
Datasource[color=blue][color=green]
>> may be a different story.)
>>
>> When I update the Display value of the underlying[/color][/color]
object,[color=blue][color=green]
>> 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[/color][/color]
ListBox[color=blue][color=green]
>> 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[/color][/color]
if[color=blue][color=green]
>> I can avoid it - there must be a way to get the ListBox
>> to refresh. Help![/color]
>
>
>.
>[/color] |  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,295 network members.
|