very basic question on listboxes and arrays

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
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
 
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.
 
Back
Top