Results 1 to 27 of 27

Thread: VB.NET: Transferring Data From Form to Form....[Resolved]

  1. #1

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    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.

  2. #2
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    VB Code:
    1. 'in form1
    2. public s as string
    3. s=textbox1.text
    4. dim f as new form2
    5. f.showdialog
    6.  
    7. 'in the form2
    8. dim f1 as new form1
    9. textbox1.text=f1.s
    Last edited by mar_zim; Sep 29th, 2004 at 01:50 AM.

  3. #3

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    still cannot....

    TextBox1 in form2 got an error say not declared yet..

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    you must draw a textbox in design mode of your form2.

    i just assume that you have a textbox named textbox1 in your form2.

  5. #5

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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...

  6. #6
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    ok lets do it this way..
    VB Code:
    1. 'i declare public variable so that it can access through out the project when you instantiate the form.
    2. 'in the form 1
    3. public s as string
    4. 'lets assume that you have a textbox in form named: textbox1
    5. 'in the button click event
    6. s=textbox1.text
    7. dim f2 as new form2()
    8. f2.showdialog()
    9.  
    10. 'in the form2
    11. 'lets assume that you have a textbox named: textbox2.
    12. dim f1 as new form1()
    13. me.textbox2.text = f1.s

    i hope that make sense..

  7. #7

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Thanks.....but still cannot...

    I think because you declare too much New in form1 and form2...

    That why......form2 will always be blank...

  8. #8
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552

  9. #9
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    you cannot use the form if you will not instantiate it.

    that's the purpose of New.

  10. #10
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    hey toytoy...how about this..
    in form1
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim f As New Form2()
    3.         f.TextBox2.Text = Me.TextBox1.Text 'passing text in the form2
    4.         f.Show()
    5.     End Sub

  11. #11

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    got it finally....


    Thanks fret

  12. #12
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    Last edited by fret; Sep 28th, 2004 at 11:06 PM.

  13. #13

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Beside passing data directly from textbox....

    Could it be possible if i use string to transfer data in the same Scenario as above....

    Thanks

  14. #14
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251
    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
    ~Ryan





    Have I helped you? Please Rate my posts.

  15. #15

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230

    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.

  16. #16

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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..


  17. #17
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    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?

  18. #18

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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.

  19. #19
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    why don't you change it in this way, just a suggestion.
    in form1:
    VB Code:
    1. 'next button
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         Dim f As New Form2()
    4.         Me.AddOwnedForm(f)
    5.         f.TextBox1.Text = Me.TextBox1.Text
    6.         f.Show()
    7.         Me.Hide()
    8.  
    9.     End Sub
    in form2:
    VB Code:
    1. Dim f As Form1
    2.     'back button
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         f = Me.Owner
    5.         Close()
    6.         f.Show()
    7.     End Sub

  20. #20

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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.

  21. #21
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    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.

  22. #22

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    Cannot....

    f.ListBox1.Items.Clear()

    the f is not declared in form2...

  23. #23
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    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.

  24. #24

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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..

  25. #25
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    no problem...
    happy coding

  26. #26

    Thread Starter
    Addicted Member toytoy's Avatar
    Join Date
    Jul 2004
    Posts
    230
    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...


  27. #27
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472
    like what you've said you know there a lots of way on how to come up with. It's up to you on what would be the better.
    ok, put [solved] or [resolved] to your topic.
    cheers mate.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width