How to pass id(value) to another form in vb.net
How to pass id(value) to another form in vb.net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jun 7, 2013, 2:30 AM
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.
VulpesPosted Jun 6, 2013, 5:05 PM
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