Click here to Skip to main content
15,902,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I was wondering how can i pass text between two windows forms. i am currently using vb.net with .net framework 4. I have a mainform with 2 buttons (btnbrowse, btnclose) & 2 textboxs(txtName, txttype). When the user clicks btnbrowse i want form2 (dialogbox) do show and then the user able to select item from combobox. when the user clicks ok i want it to pass the data back to MAINFORM on txttype.

VB
Public Property PassType As String
    Get
        Return txttype.Text
    End Get
    Set(ByVal value As String)
        txttype.Text = value
    End Set
End Property



VB
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MAINFORM.TXTTYPE.TEXT = PassType
        Me.Close()
    End Sub


it still does not work...is there something really wrong with this....cos im confusing my self...any help would be great.

thanks in advance.
Posted

This is a popular question of Form collaboration. The most robust way of doing it is implementation of appropriate interface in the form class.

Please see my past solution explaining that: How to copy all the items between listboxes in two forms[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 1-Nov-11 9:01am    
5'ed - I've lost track of how many times you have answered this question :)
Sergey Alexandrovich Kryukov 1-Nov-11 11:33am    
Me too. Thank you, Espen.
--SA
SIFNOk 2-Nov-11 7:28am    
yeeeahh.. beeen a great help. thanks *derppp
Sergey Alexandrovich Kryukov 2-Nov-11 11:54am    
Huh?
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900