very basic question on listboxes and arrays

C

COHENMARVIN

I have an array of structures that I'd like to put in a listbox. I'd
like to concatenate some of the fields together to display, but I also
need one of the fields to be the value of the item.
Now I could add the structures one by one to the listbox
(with .items.add(item)), but I think I would need a 'tostring' method
in the structure. Is that possible to do?
Or maybe I could set the listbox datasource to the entire array, but
then I don't know how to make some of the fields appear as a display
in the listbox, and one of the fields come back as the actual value of
a row in the listbox.
These are basic operations, but after reading a VB book, I still don't
know how to do them.
Thanks,
Marvin
 
T

Tom Shelton

I have an array of structures that I'd like to put in a listbox. I'd
like to concatenate some of the fields together to display, but I also
need one of the fields to be the value of the item.
Now I could add the structures one by one to the listbox
(with .items.add(item)), but I think I would need a 'tostring' method
in the structure. Is that possible to do?
Or maybe I could set the listbox datasource to the entire array, but
then I don't know how to make some of the fields appear as a display
in the listbox, and one of the fields come back as the actual value of
a row in the listbox.
These are basic operations, but after reading a VB book, I still don't
know how to do them.
Thanks,
Marvin

By default, the listbox will call the .ToString method for it's
display value. You can override the .ToString if you would like, or
you can set the listbox's DisplayMember property to the name of the
property you would like it to use. As for the value, you can set the
ValueMember property of the listbox to the name of the property to
draw the memeber from.
 

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