Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Please help me, I have a project and have 3 form, form 1 is for name and lastname, form 2 is for school and university, form 3 is to display all the data ..How can i display data from textbox1 in form 1 and form 2 to form 3??
 

 
Look Guys ..
To make my problem clear
I have two forms..
 
Form 1: 1 textbox and 1 button ( button don't show the name that user enter in txtbox but open form 2)
 
Form 2: 1 txtbox and button, (in txtbox form 1 user enter name) in this txtbox form 2 the user enter his lastname...The button will show a msgbox wich show up the name and lastname..
 

how can i do it?
 

I tried like thi: but it doesn't work out :/
 
Private Sub Command1_Click()
Static name As Integer
Static lastname As Integer
firstname = txtFirstName.Text
LastName = txtLastName.Text
txtFirstName.Text = Form1.txtFirstName.Text
txtLastName.Text = Form2.txtLastName.Text
 
both = (Form1.txtFirstName.Text " & & " Form2.txtLastName.Text)
MsgBox (both)
 
End Sub
Posted 27-Dec-12 10:18am
San Dra391
Edited 31-Dec-12 9:37am
v4
Comments
richcb at 27-Dec-12 15:19pm
   
Post the code of the forms your have so far.
San Dra at 30-Dec-12 10:20am
   
How?
Sergey Alexandrovich Kryukov at 27-Dec-12 15:31pm
   
Not quite a good question. What do you mean how? How to write code? What part of it? It's hard to help if you don't explain a particular problem.
—SA
San Dra at 30-Dec-12 10:21am
   
I mean where I have to write the code?
 

 
Look Guys ..
To make my problem clear
I have to forms..
Form 1: 1 textbox and 1 button ( button don't show the name that user enter in txtbox but open form 2)
Form 2: 1 txtbox and button, (in txtbox form 1 user enter name) in this txtbox form 2 the user enter his lastname...The button will show a msgbox wich show up the name and lastname..
 

how can i do it?
 

I tried like thi: but it doesn't work out :/
 
<pre lang="vb">Private Sub Command1_Click()
Static name As Integer
Static lastname As Integer
firstname = txtFirstName.Text
LastName = txtLastName.Text
txtFirstName.Text = Form1.txtFirstName.Text
txtLastName.Text = Form2.txtLastName.Text
 
both = (Form1.txtFirstName.Text " & & " Form2.txtLastName.Text)
MsgBox (both)
 
End Sub</pre>
 
I have stuck
Sergey Alexandrovich Kryukov at 30-Dec-12 13:14pm
   
OK, is your problem solved by now?
—SA
San Dra at 31-Dec-12 7:04am
   
Not quite well...I'm still trying, searching on net so
Sergey Alexandrovich Kryukov at 31-Dec-12 11:55am
   
I asked because when you sent your previous comment you had a solution or two. So, I asked, without reading them, is you still need help, with what...
—SA
San Dra at 31-Dec-12 13:58pm
   
with the same problem, i thought it could work, but still the first question
ridoy at 28-Dec-12 2:27am
   
Remember we can't see your project even what you do in your code,so to get better help you need to show us what you had tried and post your code here.
San Dra at 30-Dec-12 10:22am
   
Check out the question update I made :)
Hope to help me...
Christian Graus at 31-Dec-12 14:37pm
   
Consider using a non retarded subject line. Your tags tell us you're using VB, and the fact you're asking a question tells us you want help.
San Dra at 31-Dec-12 16:39pm
   
yess..You are finding good subject for my question
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yo might to create some container , where you can store all data from various forms.
But one thing that you should consider, this holder/container must behaves like singleton! Use singleton pattern for it!
 
And one important moment, in future , please , primiraly try to write some code by yourself , and only in case of some confusion or error , ask comunnity for help!
  Permalink  
Comments
San Dra at 30-Dec-12 10:24am
   
I have a project with student grades, but include their names..now how do I display in the end all the data from forms previous..?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].
 
Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.
 
Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].
 
I would also add that your design does not seem good. I would strongly advise to review it, but I cannot suggest any particular design as right now I don't know your goals. First of all, I would avoid multi-form design at all. In most cases, one but more complex form is quite enough, but it also more convenient for the users. What you have now as a separate form can become some container control. Such as Panel or TabPage. You can hide one panel and show another one, you can activate different pages of TabControl, one at a time, or even develop more complex dockable design (similar to that of Visual Studio). Please think about it.
 
Happy New Year!
 
—SA
  Permalink  
Comments
San Dra at 31-Dec-12 16:41pm
   
Thank you very much..
 
Happy new year too ^_^
Sergey Alexandrovich Kryukov at 31-Dec-12 17:38pm
   
Thank you,
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Place TextBox or LabelBox, or DataGridView in Your 3rd Form
Here i've Write Code to Display Details from Form1 and From2 to TextBox(s) in Form3...
 
txtFristName.Text = Form1.txtFirstName.Text
 

Write Similar Code for all Fields,
 
If this answer not you Looking for? Just Improve your Question and Be Specific with your Problem...
  Permalink  
v2
Comments
Christian Graus at 28-Dec-12 0:46am
   
This is really awful, about the worst possible solution. No form should ever expose it's UI elements.
Ashok19r91d at 28-Dec-12 0:55am
   
Who say so? Objects Properties can be right to access from Anywhere in Project... Only thing Your Object have Modifiers Property of Object to Friend...
 
This Solution not applicable for Webforms...
Christian Graus at 28-Dec-12 2:00am
   
Sure - there's always a difference between what a beginner will do because it works, and what a real programmer does to write a clean, maintainable system. This will work. It's just ugly and not suitable for real world systems.
Ashok19r91d at 28-Dec-12 2:17am
   
If so Ignore my My Solution, Sorry for wasting your time...
Sergey Alexandrovich Kryukov at 31-Dec-12 17:36pm
   
It's too late to ignore... :-) Or does it mean that you don't want to listen to anything negative and hence don't want to learn on your mistakes? Christian meant to help you to learn one really practically important principle, which could be really useful for you, and what? — would you rather tend to close your eyes on good advice? If this is so, you can hardly learn...
—SA
San Dra at 30-Dec-12 10:25am
   
I tried it but it didn't recognize the element form1.txtFirstName.Text in form 2 to display..
Ashok19r91d at 30-Dec-12 23:13pm
   
OK, txtFirstName is the ObjectName, Replace that with Your TextBox's Name...
San Dra at 31-Dec-12 7:06am
   
that works, it doesn't compile at all...but only in one form
Ashok19r91d at 31-Dec-12 7:12am
   
CHeck Back Your Another Question, I've Update Full Source there...
San Dra at 31-Dec-12 13:59pm
   
Ok

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 235
4 Suraj Sahoo | Coding Passion 175
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 31 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100