Listbox item not a string object, updating items

C

Claire

As a Listbox.item, rather than using a string I'm using a ListItems object,
overriding the ToString method
When I add items to listbox.items, my strings are shown correctly.
On the otherhand, when I update the "value" field the listbox doesn't update
to reflect the new value.
What do I need to do to the following code to correct this please (if it's
possible) ?

public class ListItems

{

public bool IsUser = false;

public string value = "";


public ListItems(string Text, bool IsUser)

{

this.IsUser = IsUser;

value = Text;

}

public override string ToString()

{

return value;

}

}
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


The class seems fine, I think that what happen is that the listbox has no
way to know (implicitly) that the content of the item changed, so basically
you need to force it to update, I can think of 3 methods ( not sure of the
best nor if they work )

1- Call Invalidate on the listbox, it does force a paint on it. A similar
approach will be calling Refresh()
2- Call ListBox.RefreshItem( index )
3- Remove/Insert the item in the Items collection.


Cheers,
 

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