I am trying to populate a ListView when clicking on a button from a different form from the form the ListView is on. I created a Method in Form1 to use in Form2 and pass the parameters to the method in Form1 then populate the ListView. When I debug I am getting all the correct values passed over, but the ListView is still not populating. No matter if I set the Modifier property to Public for the ListView or not.Here is my code which I dumbed done for simplicity.
Form1 (Only has a ListView and a button to open Form2)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void setLvi(string name, string age, string dob)
{
ListViewItem lvi = new ListViewItem(name);
lvi.SubItems.Add(age);
lvi.SubItems.Add(dob);
listView1.Items.Add(lvi);
}
private void button1_Click(object sender, EventArgs e)
{
Form2 fm3 = new Form2();
fm3.Show();
}
}
}
Form 2 (It only has a button that should populate the ListView)
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 fm2 = new Form1();
string name2 = "Chris";
string age2 = "23";
string dob2 = "12/19/1989";
fm2.setLvi(name2, age2, dob2);
}
}
}