0

i've been reading a lot about references but i'm not quite sure how to use them. I have form1 that opens form2, form2 gathers data from the user and turn that into an object, i need to send that object back to form1 to make an array of that object. I've been unable to do that simple thing for quite some time today. Thanks in advance!

public Form1()
        {
            InitializeComponent();
        }

In Form2

private void cmdSavePlayer_Click(object sender, EventArgs e)
        {

                CNode newP = new CNode();
                newP.IdPlayer= Convert.ToInt32(txtId.Text);
                newP.PlayerName = txtName.Text;
                newP.Level = Convert.ToInt32(txtLevel.Text);
                newP.TotalScore = Convert.ToInt32(txtScore.Text);
        }

Now i need to send that newP back to form1.

JuanPa
  • 59
  • 9
  • 1
    What do you have so far? What have you tried/have not tried? – Brad Jun 07 '18 at 19:27
  • 1
    You can create the object internally in form2, and expose a public function in form2 called `getObject()` or something that returns an object of the desired type. Then in Form1, after `Form2.ShowModal()` you can make your validations and retrieve the object via `Form2.GetObject()`. – Phiter Jun 07 '18 at 19:28
  • Without seeing the code or a more specific problem this is just a duplicate of "Pass data between forms" – BradleyDotNET Jun 07 '18 at 19:29
  • I've been trying what i saw in other responses, but cannot figure it out myself to make it work. – JuanPa Jun 07 '18 at 19:29
  • Then you need to be a *lot* more specific about what is going wrong. There's a *lot* of valid ways to do this. – BradleyDotNET Jun 07 '18 at 19:30
  • There, i think its better. – JuanPa Jun 07 '18 at 19:35

0 Answers0