|
-
Sep 28th, 2004, 09:28 PM
#1
Thread Starter
Addicted Member
VB.NET: Transferring Data From Form to Form....[Resolved]
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2.....
That means after i fill in any data in textBox1 and click Next button...
It will bring me to form2....and there the data that i key in form1 will appear to form2 in textbox2
Thanks
Last edited by toytoy; Sep 29th, 2004 at 01:51 AM.
-
Sep 28th, 2004, 09:46 PM
#2
VB Code:
'in form1
public s as string
s=textbox1.text
dim f as new form2
f.showdialog
'in the form2
dim f1 as new form1
textbox1.text=f1.s
Last edited by mar_zim; Sep 29th, 2004 at 01:50 AM.
-
Sep 28th, 2004, 10:02 PM
#3
Thread Starter
Addicted Member
still cannot....
TextBox1 in form2 got an error say not declared yet..
-
Sep 28th, 2004, 10:11 PM
#4
you must draw a textbox in design mode of your form2.
i just assume that you have a textbox named textbox1 in your form2.
-
Sep 28th, 2004, 10:15 PM
#5
Thread Starter
Addicted Member
you means both form1 and form2 share the same TextBox1....
Even if i do the above, textbox1 in form2 will still be blank without the error message...
-
Sep 28th, 2004, 10:25 PM
#6
ok lets do it this way..
VB Code:
'i declare public variable so that it can access through out the project when you instantiate the form.
'in the form 1
public s as string
'lets assume that you have a textbox in form named: textbox1
'in the button click event
s=textbox1.text
dim f2 as new form2()
f2.showdialog()
'in the form2
'lets assume that you have a textbox named: textbox2.
dim f1 as new form1()
me.textbox2.text = f1.s
i hope that make sense..
-
Sep 28th, 2004, 10:30 PM
#7
Thread Starter
Addicted Member
Thanks.....but still cannot...
I think because you declare too much New in form1 and form2...
That why......form2 will always be blank...
-
Sep 28th, 2004, 10:32 PM
#8
Fanatic Member
-
Sep 28th, 2004, 10:33 PM
#9
you cannot use the form if you will not instantiate it.
that's the purpose of New.
-
Sep 28th, 2004, 10:35 PM
#10
Hyperactive Member
hey toytoy...how about this..
in form1
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2()
f.TextBox2.Text = Me.TextBox1.Text 'passing text in the form2
f.Show()
End Sub
-
Sep 28th, 2004, 10:38 PM
#11
Thread Starter
Addicted Member
got it finally....
Thanks fret
-
Sep 28th, 2004, 10:39 PM
#12
Hyperactive Member
Last edited by fret; Sep 28th, 2004 at 11:06 PM.
-
Sep 28th, 2004, 11:26 PM
#13
Thread Starter
Addicted Member
Beside passing data directly from textbox....
Could it be possible if i use string to transfer data in the same Scenario as above....
Thanks
-
Sep 28th, 2004, 11:37 PM
#14
Addicted Member
Originally posted by toytoy
Beside passing data directly from textbox....
Could it be possible if i use string to transfer data in the same Scenario as above....
Thanks
yes...you are essentially doing that by transferring textbox to textbox
-
Sep 28th, 2004, 11:53 PM
#15
Thread Starter
Addicted Member
VB.NET: Transferring Data From Form to Form (Using the owner thing method)
for the string part...i solve it with:
Code:
Dim s As String
Dim f As New Form2
s = textBox1.Text
f.textBox2.Text = s 'passing text to form2
f.Show()
Me.Hide()
Now another problem is i am using the owner thing..
Which means in form1....
Code:
Private f As New form2
Dim s As String
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
s = cbo.SelectedItem
f.textBox2.Text = s 'passing text in the form2
f.Show()
Me.Hide()
End Sub
In form2.......
Code:
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
Me.Owner.Show()
Me.Hide()
End Sub
Which means i cannot use the f.textbox2.text = s in form1.....the program will get hang there for quite long before getting the data there when i run...
Last edited by toytoy; Dec 3rd, 2004 at 07:40 AM.
-
Sep 29th, 2004, 12:17 AM
#16
Thread Starter
Addicted Member
oh....
forget that i put something in form2 loading part..
The program can still be works with the owner thing when i delete that part in form2 loading..
-
Sep 29th, 2004, 12:25 AM
#17
Hyperactive Member
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
Me.Owner.Show()
Me.Hide()
End Sub
dunno this part, you mean you want to go back to the form who opens the form2? is that?
-
Sep 29th, 2004, 12:32 AM
#18
Thread Starter
Addicted Member
yeah.... it' s also must be able to click back
but i want to use string and send over to another textbox in form2...
the string are from Xml...
that' s why i am using LoadXml() to load the string from form1 and then show it to the textbox in form2
Last edited by toytoy; Sep 29th, 2004 at 12:54 AM.
-
Sep 29th, 2004, 12:46 AM
#19
Hyperactive Member
why don't you change it in this way, just a suggestion.
in form1:
VB Code:
'next button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2()
Me.AddOwnedForm(f)
f.TextBox1.Text = Me.TextBox1.Text
f.Show()
Me.Hide()
End Sub
in form2:
VB Code:
Dim f As Form1
'back button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
f = Me.Owner
Close()
f.Show()
End Sub
-
Sep 29th, 2004, 01:14 AM
#20
Thread Starter
Addicted Member
For the owner thing...
say i want to click back...how to i actually clear the listbox items in previous form...
Thanks
Last edited by toytoy; Sep 29th, 2004 at 01:34 AM.
-
Sep 29th, 2004, 01:25 AM
#21
Hyperactive Member
Originally posted by toytoy
For the owner thing...
say i want to click back...how to i actually clear the listbox items in previous form...
Thanks
add this on the button back...
f.ListBox1.Items.Clear() before showing the owner form.
-
Sep 29th, 2004, 01:27 AM
#22
Thread Starter
Addicted Member
Cannot....
f.ListBox1.Items.Clear()
the f is not declared in form2...
-
Sep 29th, 2004, 01:31 AM
#23
Hyperactive Member
hey sorry for that because i considered the code above i suggest and add the f.ListBox1.Items.Clear(). Just try the code i suggest and it works well.
-
Sep 29th, 2004, 01:36 AM
#24
Thread Starter
Addicted Member
oh.....its alright...
i just change and add in the title where the owner thing starts...
i hope....it will not confuse you guys which method i use..
-
Sep 29th, 2004, 01:39 AM
#25
Hyperactive Member
no problem...
happy coding
-
Sep 29th, 2004, 01:42 AM
#26
Thread Starter
Addicted Member
finally, i solve it....
i put the clear() thing in form1...
that means i clear the listbox first before going to form2..
thus, when i click back....all are clear already...
-
Sep 29th, 2004, 01:47 AM
#27
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
|