Listbox repaint

  • Thread starter Thread starter Randy Riness
  • Start date Start date
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
 
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
 
* "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>
 
Back
Top