jason m
jason m

Reputation: 6835

C# Listbox: Display custom items in listbox

I have an object I created in C#, lets call it "listBoxCustom".

I want to store listBoxCustom in my listbox object, and i have a number of listBoxCustom objects.

I want to display a given name that I set for each object in the listbox, but as of right now it is displaying "myProject.listBoxCustom" in the nodes of the listbox, for as many items as I have added.

What do I need to do such that it will display the correct name that I want? I am assuming I need to create a certain property of my object and the listbox will by default try and access this, I am just not sure what it is.

Please let me know if you need additional detail, and thank you in advance.

Upvotes: 4

Views: 2070

Answers (1)

Tomas Voracek
Tomas Voracek

Reputation: 5914

Simply override ToString method in your listBoxCustom class.

Upvotes: 9

Related Questions