basic listbox question

G

Guest

How do I add an item to the listbox and label it? The "...Items.Add" property
only takes one argument. That confuses me. for example:

ListBox.Items.Add("My Car", picture object); //this does not work

How would I store picture objects but label them with strings that show in
the list?

Do I first add the object and then label it with another command or am I
going down the "wrong path" here?
 
N

Nicholas Paldino [.NET/C# MVP]

You are going down the wrong path. As stated in a previous response to
your questions, the label for the item in the listbox is the result of
calling ToString on the item which is stored in the listbox.

You can always provide a wrapper class which will return what you want
through ToString, while returning the actual object through another
property.

Hope this helps.
 

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