Plohej Plohej - 3 months ago 22
C# Question

How to get info from another form?

I have a problem where I can't get information from a second form in C#.

I made a easy program to add some names to a

. And somehow I cannot get the name from second form.

Here's code:

// this is second form
private String name { get; set; }
private void button1_Click(object sender, EventArgs e)
name = textBox1.Text;


// and first form on button click AddPerson()
Form2 basicPerson = new Form2();

ListViewItem item = new ListViewItem(basicPerson.Name);

With this code, result I am getting is
with "Form2" name. Does
somehow kill the
variable? How to make this work?

Thanks for help!


The basicPerson.Name is not the same as the

C# is case-sensitive.

The basicPerson.Name is the Control.Name property (the Form class descends from the Control class). And the Control.Name indeed returns a form name.

Read the Though you better change the property name to avoid future misunderstandings.

And once you switch to name (or to a better property name), you will find out that you need to change an accessibility level of the property to public or internal to be able to read it.