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.



form1



form 2










share|improve this question























  • 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














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.



form1



form 2










share|improve this question























  • 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












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.



form1



form 2










share|improve this question















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.



form1



form 2







c# winforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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












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!






share|improve this answer





























    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);






    share|improve this answer






















    • 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










    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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

























    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!






    share|improve this answer


























      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!






      share|improve this answer
























        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!






        share|improve this answer














        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!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 10 at 20:31









        Jimi

        5,84321032




        5,84321032










        answered Nov 10 at 19:18









        bolkay

        3478




        3478






















            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);






            share|improve this answer






















            • 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














            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);






            share|improve this answer






















            • 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












            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);






            share|improve this answer














            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);







            share|improve this answer














            share|improve this answer



            share|improve this answer








            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
















            • 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

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3