![]() |
|
Exchange of data between forms [C#] - Printable Version +- LCKB (https://lckb.dev/forum) +-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109) +--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196) +---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192) +---- Thread: Exchange of data between forms [C#] (/showthread.php?tid=2027) |
- Paramount - 08-06-2013 Hey guys. Im gonna get the data from Form1 to Form2. This is mine code: Form1 form = new Form1(); this.hash_user.Text = form.textBox36.Text; this.hash_user.Text is the field from the current form, textBox36 is the field from Form1. This does not work. Field in Form2 is still empty. Although I have already tried to use form.ShowDialog() and form.Show() but nothing happens Any idea how to do it? Thanks in advance. - someone - 08-06-2013 Try this: Form1 form = new Form1(); form.ShowDialog(); this.hash_user.Text = form.textBox36.Text; The form with ShowDialog is a Modal form(it means it Blocks at ShowDialog), the with Show it is not a modal form(it will load the form and continue with the program while the form is running). Usually when you close The form The controls on that form deinitializes, it is better to save the data in a public variable(or a private one and access it thru public methods); private struct MyData{ public string textBox1 }; public MyData data = new MyData(); .... data.textBox1 = textBox36.Text; .... Form1 form = new Form1(); form.ShowDialog(); this.hash_user.Text = form.data.textBox1; - Paramount - 08-06-2013 I have already tried to use ShowDialog() but it does not work. hash_user is still empty... - someone - 08-06-2013 Read the full reply: Usually when you close The form The controls on that form deinitializes, it is better to save the data in a public variable(or a private one and access it thru public methods); private struct MyData{ public string textBox1 }; public MyData data = new MyData(); .... data.textBox1 = textBox36.Text; .... Form1 form = new Form1(); form.ShowDialog(); this.hash_user.Text = form.data.textBox1; public string data; .... data= textBox36.Text; .... Form1 form = new Form1(); form.ShowDialog(); this.hash_user.Text = form.data; - Paramount - 08-06-2013 Oh, I havent observed it! Thank you very much! Workz! |