Question Passing Parameter between forms

PatelNehal4u

Active member
Joined
Apr 6, 2009
Messages
25
Programming Experience
1-3
:confused:I had two forms, first forms shows all the task details in a list and user select any task and the second form shows the details of that task in edit mode so user can edit the record, now i don't know how to pass the Task_ID of selected item from form1 to form2.
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
There are multiple ways of passing information from one form to another (and back).
If you are just passing the value to the next form, then easiest way (IMHO) is to pass the value to a constructor of the second form.

VB.NET:
Public Class Form1

     Public Sub Button1Click(ByVal sender as Object, ByVal e As EventArgs) Handles Button1.Click
         
         'Passes the value of TextBox txtTextBoxID to the constructor of Form2
         Dim frmNewForm as New Form2(txtTextBoxID.Text.Trim)
         frmNewForm.Show()
     End Sub

End Class

Public Class Form2

     Dim TextIDFromForm1 As String = ""
     Public Sub New(ByVal PassTextID As String)
          InitializeComponents()
         
          'The value passed from Form1 to this constructor is 
          ' temporarily in PassTextID. So we transfer the value to 
          ' a variable on Form2 to hold it for the duration of this
          ' instance of Form2
          TextIDFromForm1 = PassTextID
     End Sub
End Class
 
Top Bottom