VB.NET Pass variable from 2nd form to main form

I am running into an issue where I need to pass value from a 2nd form that I open to my original main form.  What I did was create a lookup form that has a datagridview.  From my main form, I click on a button that would open up the 2nd form.  If I  double click on which ever row from the datagridview on the 2nd form, I want to transfer the ID of that rowindex back to the main form and input that to the txtID.Text from the main form, then close the 2nd form.

I did a bit of research but can't seem to get what I need working.  Can anyone assisst me with some example?

Who is Participating?
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.

Jorge PaulinoIT Pro/DeveloperCommented:
Here's a way ...

' First Form
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm As New Form2
        If frm.ID <> 0 Then
        End If
    End Sub
End Class
' Second Form
Public Class Form2
    Private _ID As Integer
    Public Property ID() As Integer
            Return _ID
        End Get
        Set(ByVal value As Integer)
            _ID = value
        End Set
    End Property
    ' Close button
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.ID = 123
    End Sub
End Class

Open in new window


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
holemaniaAuthor Commented:
Awesome.  That worked!!
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.