Adding objects with a custom label into a ListBox in C#/.Net

A .Net ListBox can contain elements of any class by using the template collection class List<>.

The ListBox will display labels by iterating through the list and calling the ToString() method of each element.

You might want to change this label for your own classes by overriding ToString() method, otherwise you end up with labels such as “Namespace_name.Object_name”.

Advertisements