S
Sin Jeong-hun
class SomeClass
{
...
public override string ToSting
{
.... return different values according to its state.
}
}
in the form's code
SomeClass s = new SomeClass();
MyListbox.Items.Add(s);
If I add it like that, the Listbox will use ToString() method to
display the SomeClass. But the problem is when the SomeClass's inner
state has changed and therefore ToString() value is changed, the
Listbox doesn't reflect the change automatically. What could be the
best clean solution? The only way I can think of is not to add the
SomeClass directly, but add its ToString() value to the Listbox and
maintain an independent list of SomeClass'. Then when the SomeClass is
changed I may manually change the item with the SomeClass's newest
ToString() value.
But I'm not sure it's the best way. Isn't there any better way like,
ListBox.UpdateItemText(int index) or interface
ListBox.NotifiableObject (I made them up, they are not real)?
{
...
public override string ToSting
{
.... return different values according to its state.
}
}
in the form's code
SomeClass s = new SomeClass();
MyListbox.Items.Add(s);
If I add it like that, the Listbox will use ToString() method to
display the SomeClass. But the problem is when the SomeClass's inner
state has changed and therefore ToString() value is changed, the
Listbox doesn't reflect the change automatically. What could be the
best clean solution? The only way I can think of is not to add the
SomeClass directly, but add its ToString() value to the Listbox and
maintain an independent list of SomeClass'. Then when the SomeClass is
changed I may manually change the item with the SomeClass's newest
ToString() value.
But I'm not sure it's the best way. Isn't there any better way like,
ListBox.UpdateItemText(int index) or interface
ListBox.NotifiableObject (I made them up, they are not real)?