passing data from one form to another

chowchow123

Active member
Joined
Sep 6, 2007
Messages
34
Programming Experience
1-3
Hi

I need to pass data from one form to another - below is the code - it doesn't seem pass the data for some reason

MainForm has the Mem_idTextBox
Manual id Form has TextBox1 - need text box value to be passed to Main Form mem_idTextBox

VB.NET:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click

        My.Forms.MainForm.Mem_idTextBox.Text = TextBox1.Text

        Me.Close()
    End Sub
Thanks
 
Hi, this is the code i would use to do the same thing, don't know if its the best practice but it works for me.
VB.NET:
mainform.mem_idtextbox.text = (from form).textbox1.text

change the (from form) to you manual id form name or what ever it is called.
 
Just create a property in the form you want to pass the data to.. i.e..

VB.NET:
Friend Property SetText as String
Get
Return me._SetText
End Get
Set (Byval value As String)
Me._SetText = Value
Me.Mem_idTextbox.Text = _SetText
End Set
End Property

From you main form after you have created an instance of it..

VB.NET:
YourForm.SetText = TextBox1.Text

This can also be done with a simple Sub method, which keeps the idea of encapsulation. This is a bit of a messy example but it shows the general idea.
 
Back
Top