How to pass id(value) to another form in vb.net
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jun 6, 2013, 1:05 PM EDT
However, a neat way is to pass the value in the constructor:
' within a method in Form 1
Dim Id As String = "suraj"
Dim f2 As New Form2(Id)
f2.Show()
' Form2
Class Form2
Inherits Form
Private Id As String ' store value in a private field
Public Sub New (ByVal Id As String)
InitializeComponent()
Me.Id = Id
End Sub
' other code
End Class
Jignesh TrivediRank #16 · 50.3K reputationPosted Jun 6, 2013, 10:30 PM EDT
hi,
Agree with Vulpes,
you can also either
1) set up some properties which will get and set values on the second form
//this is form 2 (sorry here i am providing c# code)
public string Name
{
get;
set;
}
//form1
Form2 form2 = new Form2();
form2.Name = "Jignesh";
form2.Show();
2) directly pass the values from form 1 into form 2, which will then set the values in its own global variables.
hope this will help you.