Referencing Objects in a listbox

  • Thread starter Thread starter LarryMac
  • Start date Start date
L

LarryMac

This is sort of a newbie question, but it's making me crazy.

I have a project (VB.Net) in which data is read from a source file.
That data is used to create instances of the class "OrderItem" and a
list box (Supplies) is populated with those items. This part works.

If the user double-clicks an item on the list box, it checks to see if
that item appears on another list box (On Order) to see if it has
already been ordered.

Normally, I just cast the item on the list as a string
(CStr(lstSupplies.Items(lstSupplies.SelectedIndex)) and search the
other list box for it, but this time I can't seem to cast an
"OrderItem" as a "String". I'm assuming it's because my collection is
objects and not just text strings, but I can't seem to come up with a
workaround. BTW, items are listed (sorted) by their description via a
ToString function within the class.

Any and all help is appreciated.
 
Larry,

don't cast them, call their ToString-Method to get the string with which you
are searching the second list (Actually, you already kind of wrote that
yourself in the last paragraph ;-)

Klaus
 
Thanks, I sorta knew what I was doing wrong, and almost knew what I
had to do...I just couldn't seem to make that final leap.
 
Back
Top