Avatar of ipeng
ipeng
 asked on

Selected List Value as Object

I don't even know the correct terminology for this, so I will try to explain.

I have a list box that I populate with values from an object (Item), one object per row.

lstThing

Now I want to select and use the value in that row to pass it as a reference to the object in another method.

Private Sub  xyz
' declare the variable
Dim thing As Thing
Dim addThing As AnotherThing

' I get an error with this:
getThing = lstThing.SelectedValue.ToString

'Do Stuff
addThing = _Machine.doSomething(getThing)

End Sub

Trying to pass the object associated with getThing to addThing, but get an error "Value of Type String cannot be converted..."  

VB suggests using cType to convert, but that doesn't work either.

I know it's something very elementary, but I can't figure it out!
Visual Basic.NET

Avatar of undefined
Last Comment
ipeng

8/22/2022 - Mon
Carl Tawn

Can you show us how you are populating the list?
ASKER CERTIFIED SOLUTION
Mike Tomlinson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ipeng

ASKER
Thanks for the help.    Using the CType with SelectedItem fixed it.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck