Reputation: 107
say listview in form1 has following columns Name & Email with following data like
NAME EMAIL
adam [email protected]
james [email protected]
kris [email protected]
this listview is in form1.
listview has a contextmenu with update item, say i select james row from form1 right click and select update, now form2 will be loaded which has two textboxes & i want name & email from selected row of listview to be there in that textboxes like
textbox1 = james
textbox2 = [email protected]
what im doing actually is.
on form1 ive contextmenu with item update. on the click of updatecontextmenu ill load form2 with textbox name and email. listview contains name and email as shown above. i want to place the name from the selected row in form1 from the list view to name textbox and email respectively.
i tried this.
form1:
updateToolStripMenuItem_Click(...)
{
Form3 update = new Form3();
update.ShowDialog();
}
form3:
Form3_Load(...)
{
Form1 f1 = new Form1();
string oldName = f1.listView1.SelectedItems[0].SubItems[0].Text;
string oldEmail = f1.listView1.SelectedItems[0].SubItems[0].Text;
textBox1.Text = oldName.ToString();
textBox2.Text = oldEmail.ToString();
}
but getting error InvalidArgument=Value of '0' is not valid for 'index'
Upvotes: 0
Views: 375
Reputation: 1276
You can change the constructor for the second form to:
public Form2(string name, string email)
{ ... }
In Form1 then:
Form2 update = new Form2(name, email);
Upvotes: 1