ListView Item Edit

private void editToolStripMenuItem1_Click(object sender, EventArgs e)
{
            if (listView1.FocusedItem == null) return;
            int index = listView1.FocusedItem.Index;
            PersonForm personForm1 = new PersonForm();
            personForm1.Owner = this;
            personForm1.textBox1.Text = listView1.Items[index].SubItems[0].Text;
            personForm1.textBox2.Text = listView1.Items[index].SubItems[1].Text;
            personForm1.textBox3.Text = listView1.Items[index].SubItems[2].Text;
            personForm1.textBox4.Text = listView1.Items[index].SubItems[3].Text;
            if (personForm1.ShowDialog() == DialogResult.OK)
            {
                Person p = new Person();
                p.Name = personForm1.textBox1.Text;
                p.ID = int.Parse(personForm1.textBox2.Text);
                p.Phone = personForm1.textBox3.Text;
                p.Address = personForm1.textBox4.Text;
                pList[index] = p;
                listView1.Items[index] = p.ToListViewItem();
            }
}

Leave a Reply

Your email address will not be published. Required fields are marked *