Listbox repaint

R

Randy Riness

After changing a property in an object added to a
listbox, how can I get the listbox to recall the ToString
method and display current values?

Example:
Private Sub AddToList
Dim MyObject as New MyClass
' Set property values
Lisbox.Items.Add(MyObject)
End Sub

Private Sub UpdateObject
Dim MyObject as MyClass=CType
(ListBox.SelectedItem,MyClass)
MyObject.Property="NewValue"
' Now, the object has new data
' but the old value from ToString still shows.
'What goes here to get the listbox to refresh/repaint?
End Sub

TIA
 
F

Fergus Cooney

Hi Randy,

The only way that seems to work is to reassign the list item to itself.

MyObject = ListBox1.SelectedItem
MyObject.Props = Foo
ListBox1.Items (ListBox1.SelectedIndex) = MyObject

Regards,
Fergus
 
H

Herfried K. Wagner [MVP]

* "Randy Riness said:
After changing a property in an object added to a
listbox, how can I get the listbox to recall the ToString
method and display current values?

Example:
Private Sub AddToList
Dim MyObject as New MyClass
' Set property values
Lisbox.Items.Add(MyObject)
End Sub

Private Sub UpdateObject
Dim MyObject as MyClass=CType
(ListBox.SelectedItem,MyClass)
MyObject.Property="NewValue"

Use 'DirectCast' instead of 'CType' here.

Try: 'ListBox1.Items(ListBox1.SelectedIndex) = MyObject'.
' Now, the object has new data
' but the old value from ToString still shows.
'What goes here to get the listbox to refresh/repaint?
End Sub

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 

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