Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two forms form1 and form2
form1 is the parent and form2 is its mdi child.
i have a textbox on form2
Can i access textbox value on form one ?
Posted
Updated 6-Sep-11 20:02pm
v2
Comments
Philippe Mori 6-Sep-11 20:43pm    
No need for 7 question marks, neither to make it appears urgent and you can also be a bit more careful to write correctly : application, I (capital letter), please and reply.

If the Form1 is the MDIparent, you can loop through the MdiChildren property. Something like:
C#
foreach (Form mdiChild in this.MdiChildren) {
   if (mdiChild is Form2) {
      // some code here, for example: ((Form2)mdiChild).GetTextBoxText()
   }
}

I wouldn't advice to directly get the value of a text box from the child form (even though it's possible). Instead define a method in Form2 and call that method from the previous code example. In this method get the data from the text box, possibly modify it if needed and then return it. The method could be simply:
C#
public string GetTextBoxText() {
   return this.textbox2.Text;
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Sep-11 1:54am    
My 5 -- same thing as a minute ago -- please see my (the same) answer.
--SA
Wendelius 7-Sep-11 2:01am    
Thanks.
How much longer you guys are going to torture yourself and scare off your customers with MDI? This is evil.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

—SA
 
Share this answer
 
Comments
Wendelius 7-Sep-11 2:01am    
And the same reply, but a different +5 :)
Sergey Alexandrovich Kryukov 7-Sep-11 2:07am    
Reuse, damn it :-)
Thank you, Mika.
--SA
koolprasad2003 7-Sep-11 2:02am    
nice ans.
Sergey Alexandrovich Kryukov 7-Sep-11 2:07am    
Thank you, Prasad.
--SA

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