I have two forms, form1, which the user can select the file to edit, and form2 which the user can edit the data. Below code for form1 listView in which the user selects the file to edit:
private void listView1_DoubleClick(object sender, EventArgs e)
{
_AccountData = File.ReadAllLines(listView1.SelectedItems[0].Tag.ToString());
Form2 passForm = new Form2();
passForm.ShowDialog();
}
Here is the code for the second form, in which the user should be able to edit data:
private void Form2_Load(object sender, EventArgs e)
{
Form1 f1 = new Form1();
string[] accData = f1.AccountData;
string[] test1 = accData.ToString().Split(';');
oldUsername.Text = test1[0];
oldPass.Text = test1[1];
//and so on
}
Property to pass data:
private string[] _AccountData;
public string[] AccountData
{
get { return _AccountData; }
set { _AccountData = value; }
}
This is what I use to pass data between forms, but whenever I try to display data, it always hangs on the second form, because it shows that f1.AccountData is null
, even though there is data in it (if I put a breakpoint it shows data in the first form, but it is not passed to the second).
I am relatively new to working with several forms, so I do not know for sure what needs to be edited for the code to work. Why is it showing that the value is null on the second form, when it shows value in the first form?