How to return a selected value on a form from a method of a class in

I'm writing a class library in (using Visual Studio 2015 RC).  How can I write code for a method of a class to open a form, allow the user to select an item in a listbox on the form, and have the function(the method) return the ValueMember value of the listbox and close the form?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Your form needs a custom on change event. When the value is changed fire it. In your class hook into that event.
Jacques Bourgeois (James Burger)PresidentCommented:
Open the Form with a ShowDialog command instead of Show. This freezes the calling method for as long as the form is visible on the screen.

When the user makes a selection, do not Close the Form, simply Hide it.

This will bring back the execution in you method. Because the Form is still in memory, the method can read the value in the ListBox and then Close the Form.

Dim frm As New YourForm
Dim value As Integer 'Or whatever

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Please don't query the values from your form directly. This is tight  coupling, which is makes code reuse and testability harder.

When an event sounds like overkill and you're only interested in a result, then create your own DialogResult class for this dialog and return it after the ShowDialog call.
Declan_BasileITAuthor Commented:
This was a simple solution and it worked great!  Thank you.
ste5anSenior DeveloperCommented:
Well, when it works for you, fine. But it ignores the basic prinicples of OOP design.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.