|
-
Apr 23rd, 2003, 08:33 AM
#1
Thread Starter
Junior Member
Not Getting valuefrom another form
when I click on the button1 on the form1 then I am able to go to form2 but not getting the value in the txtform2 text box.
Here is the code which i am tring
under form1:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2()
frm.Show()
End Sub
under form2:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm1 As New Form1()
txtForm2.Text = frm1.txtForm1.Text
End Sub
Reason expected !!
-
Apr 23rd, 2003, 09:43 AM
#2
Lively Member
'Dim frm1 As New Form1()' this line of code creates a brand new instance of Form1 so any values you extract from it will be it's default values. You can set up a member variable in Form2 to pass the Value from Form1.
i.e.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2()
frm.valueFromFrom1 = Me.txtForm1.Text
frm.Show()
End Sub
then in form2
Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtForm2.Text = Me.valueFromForm1
End Sub
-
Apr 23rd, 2003, 12:57 PM
#3
Fanatic Member
Or you could create a new constructor and pass the text box value when you create the new form 2 like:
VB Code:
Dim frm As New Form2(txtform1.Text)
-
Apr 24th, 2003, 04:06 AM
#4
Lively Member
if you can add it as a constructor parameter, doesn't this make the form incompatible with the form designer?
-
Apr 24th, 2003, 06:10 AM
#5
Registered User
No its not going to make it incompatiable with designer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|