Why after linking to Form the data doesn't transfer from Form2 to Form1
up vote
-1
down vote
favorite
I am trying to do a big coding project however I hit a wall.
I need to show the name and score once the data has been entered in.
I tried using youtube tutorials, classes for the code. But no such luck.
Any help would be great!
form1
:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.Show();
SudentBox.Items.Clear();
form2
:
public object StudentBox get; private set;
private void bCancel_Click(object sender, EventArgs e)
this.Close();
try
string name = txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
txtStoreScores.Text += score.ToString() + " ";
catch (Exception x)
MessageBox.Show("Please enter a number");
private void bClearScores_Click(object sender, EventArgs e)
txtName.Text = "";
txtScore.Text = "";
txtStoreScores.Text = "";
Examples of what the forms should look like with the final result.
c# winforms
add a comment |
up vote
-1
down vote
favorite
I am trying to do a big coding project however I hit a wall.
I need to show the name and score once the data has been entered in.
I tried using youtube tutorials, classes for the code. But no such luck.
Any help would be great!
form1
:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.Show();
SudentBox.Items.Clear();
form2
:
public object StudentBox get; private set;
private void bCancel_Click(object sender, EventArgs e)
this.Close();
try
string name = txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
txtStoreScores.Text += score.ToString() + " ";
catch (Exception x)
MessageBox.Show("Please enter a number");
private void bClearScores_Click(object sender, EventArgs e)
txtName.Text = "";
txtScore.Text = "";
txtStoreScores.Text = "";
Examples of what the forms should look like with the final result.
c# winforms
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am trying to do a big coding project however I hit a wall.
I need to show the name and score once the data has been entered in.
I tried using youtube tutorials, classes for the code. But no such luck.
Any help would be great!
form1
:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.Show();
SudentBox.Items.Clear();
form2
:
public object StudentBox get; private set;
private void bCancel_Click(object sender, EventArgs e)
this.Close();
try
string name = txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
txtStoreScores.Text += score.ToString() + " ";
catch (Exception x)
MessageBox.Show("Please enter a number");
private void bClearScores_Click(object sender, EventArgs e)
txtName.Text = "";
txtScore.Text = "";
txtStoreScores.Text = "";
Examples of what the forms should look like with the final result.
c# winforms
I am trying to do a big coding project however I hit a wall.
I need to show the name and score once the data has been entered in.
I tried using youtube tutorials, classes for the code. But no such luck.
Any help would be great!
form1
:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.Show();
SudentBox.Items.Clear();
form2
:
public object StudentBox get; private set;
private void bCancel_Click(object sender, EventArgs e)
this.Close();
try
string name = txtName.Text;
int score = Convert.ToInt32(txtScore.Text);
txtStoreScores.Text += score.ToString() + " ";
catch (Exception x)
MessageBox.Show("Please enter a number");
private void bClearScores_Click(object sender, EventArgs e)
txtName.Text = "";
txtScore.Text = "";
txtStoreScores.Text = "";
Examples of what the forms should look like with the final result.
c# winforms
c# winforms
edited Nov 10 at 20:26
Jimi
5,84321032
5,84321032
asked Nov 10 at 18:49
Super_Fly
486
486
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19
add a comment |
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
If I'm correct, you are trying to code a form of DialogBox
.
Say, you want to get a name from the dialog (e.g. from a TextBox
in Form2
), you can have a model like this (in Form2
of course).
public string Name
//where myTextBox is the design name of your textbox
get => myTextBox.Text;
set => myTextBox.Text=value;
Simple Ok Button
public void OkBtnClick(object sender, EventArgs e)
this.Close();
Now, you need to actually get this info to display in your Form1
. That is easy.
Just like you have started above:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.ShowDialog();
//Note that you won't be able to access form1.
SudentBox.Items.Clear();
//You can now get the name
string _nameResult=link.Name;
NameTextbox.Text=_nameResult;
I hope this gets you started!
add a comment |
up vote
0
down vote
You do this by using the property.
Add public static property on Form 2 and set the values of the text to the property respectively and then access them on the Form 1.
On Form 2 in the Ok button click event do this
public static string Name get; set;
public static string Scores get; set;
private void bOk_Click(object sender, EventArgs e)
Name = txtName.Text;
Scores = txtStoreScores.TextBox;
Then in the Form 1 OnLoad event access those properties and display them in the TextBox
private Form1_Load (object sender, EventArgs e)
StudentBox.Items.Add(string.Format("0 1", Form2.Name, Form2.Scores);
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
If I'm correct, you are trying to code a form of DialogBox
.
Say, you want to get a name from the dialog (e.g. from a TextBox
in Form2
), you can have a model like this (in Form2
of course).
public string Name
//where myTextBox is the design name of your textbox
get => myTextBox.Text;
set => myTextBox.Text=value;
Simple Ok Button
public void OkBtnClick(object sender, EventArgs e)
this.Close();
Now, you need to actually get this info to display in your Form1
. That is easy.
Just like you have started above:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.ShowDialog();
//Note that you won't be able to access form1.
SudentBox.Items.Clear();
//You can now get the name
string _nameResult=link.Name;
NameTextbox.Text=_nameResult;
I hope this gets you started!
add a comment |
up vote
0
down vote
If I'm correct, you are trying to code a form of DialogBox
.
Say, you want to get a name from the dialog (e.g. from a TextBox
in Form2
), you can have a model like this (in Form2
of course).
public string Name
//where myTextBox is the design name of your textbox
get => myTextBox.Text;
set => myTextBox.Text=value;
Simple Ok Button
public void OkBtnClick(object sender, EventArgs e)
this.Close();
Now, you need to actually get this info to display in your Form1
. That is easy.
Just like you have started above:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.ShowDialog();
//Note that you won't be able to access form1.
SudentBox.Items.Clear();
//You can now get the name
string _nameResult=link.Name;
NameTextbox.Text=_nameResult;
I hope this gets you started!
add a comment |
up vote
0
down vote
up vote
0
down vote
If I'm correct, you are trying to code a form of DialogBox
.
Say, you want to get a name from the dialog (e.g. from a TextBox
in Form2
), you can have a model like this (in Form2
of course).
public string Name
//where myTextBox is the design name of your textbox
get => myTextBox.Text;
set => myTextBox.Text=value;
Simple Ok Button
public void OkBtnClick(object sender, EventArgs e)
this.Close();
Now, you need to actually get this info to display in your Form1
. That is easy.
Just like you have started above:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.ShowDialog();
//Note that you won't be able to access form1.
SudentBox.Items.Clear();
//You can now get the name
string _nameResult=link.Name;
NameTextbox.Text=_nameResult;
I hope this gets you started!
If I'm correct, you are trying to code a form of DialogBox
.
Say, you want to get a name from the dialog (e.g. from a TextBox
in Form2
), you can have a model like this (in Form2
of course).
public string Name
//where myTextBox is the design name of your textbox
get => myTextBox.Text;
set => myTextBox.Text=value;
Simple Ok Button
public void OkBtnClick(object sender, EventArgs e)
this.Close();
Now, you need to actually get this info to display in your Form1
. That is easy.
Just like you have started above:
private void bNew_Click(object sender, EventArgs e)
score link = new score();
link.ShowDialog();
//Note that you won't be able to access form1.
SudentBox.Items.Clear();
//You can now get the name
string _nameResult=link.Name;
NameTextbox.Text=_nameResult;
I hope this gets you started!
edited Nov 10 at 20:31
Jimi
5,84321032
5,84321032
answered Nov 10 at 19:18
bolkay
3478
3478
add a comment |
add a comment |
up vote
0
down vote
You do this by using the property.
Add public static property on Form 2 and set the values of the text to the property respectively and then access them on the Form 1.
On Form 2 in the Ok button click event do this
public static string Name get; set;
public static string Scores get; set;
private void bOk_Click(object sender, EventArgs e)
Name = txtName.Text;
Scores = txtStoreScores.TextBox;
Then in the Form 1 OnLoad event access those properties and display them in the TextBox
private Form1_Load (object sender, EventArgs e)
StudentBox.Items.Add(string.Format("0 1", Form2.Name, Form2.Scores);
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
add a comment |
up vote
0
down vote
You do this by using the property.
Add public static property on Form 2 and set the values of the text to the property respectively and then access them on the Form 1.
On Form 2 in the Ok button click event do this
public static string Name get; set;
public static string Scores get; set;
private void bOk_Click(object sender, EventArgs e)
Name = txtName.Text;
Scores = txtStoreScores.TextBox;
Then in the Form 1 OnLoad event access those properties and display them in the TextBox
private Form1_Load (object sender, EventArgs e)
StudentBox.Items.Add(string.Format("0 1", Form2.Name, Form2.Scores);
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
add a comment |
up vote
0
down vote
up vote
0
down vote
You do this by using the property.
Add public static property on Form 2 and set the values of the text to the property respectively and then access them on the Form 1.
On Form 2 in the Ok button click event do this
public static string Name get; set;
public static string Scores get; set;
private void bOk_Click(object sender, EventArgs e)
Name = txtName.Text;
Scores = txtStoreScores.TextBox;
Then in the Form 1 OnLoad event access those properties and display them in the TextBox
private Form1_Load (object sender, EventArgs e)
StudentBox.Items.Add(string.Format("0 1", Form2.Name, Form2.Scores);
You do this by using the property.
Add public static property on Form 2 and set the values of the text to the property respectively and then access them on the Form 1.
On Form 2 in the Ok button click event do this
public static string Name get; set;
public static string Scores get; set;
private void bOk_Click(object sender, EventArgs e)
Name = txtName.Text;
Scores = txtStoreScores.TextBox;
Then in the Form 1 OnLoad event access those properties and display them in the TextBox
private Form1_Load (object sender, EventArgs e)
StudentBox.Items.Add(string.Format("0 1", Form2.Name, Form2.Scores);
edited Nov 10 at 21:25
answered Nov 10 at 19:14
Junaid Sultan
1201111
1201111
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
add a comment |
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
Ok where would you add the set and get in the code
– Super_Fly
Nov 10 at 21:20
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
You don't need to add the get and set for a property.
– Junaid Sultan
Nov 10 at 21:23
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242301%2fwhy-after-linking-to-form-the-data-doesnt-transfer-from-form2-to-form1%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I have no idea what "linking data to form means", but there is such a thing as DataBinding - if the 2 forms share the same datasource, data added in one form is automagically available in the other. No luck required.
– Disaffected 1070452
Nov 10 at 19:19