Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Listbox: Display custom items in listbox

Tags:

c#

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.

like image 740
jason m Avatar asked Jan 20 '23 04:01

jason m


1 Answers

Simply override ToString method in your listBoxCustom class.

like image 119
Tomas Voracek Avatar answered Jan 30 '23 06:01

Tomas Voracek