Edit row in ListView (C# Window program)

Need help with ListView in C# windows programming.

I have a ListView in detail mode. I click add button, popup prompts me for column data, then I add the data to the ListView which appears as next row.

Imagine I’ve added 3 rows, I want to go and edit the second. I highlight it then click on button Edit. the same popup prompts me with the existing data so I can modify it then click submit on the popup.

The new data should replace the old data in the 2nd row. I don’t know how to do that.

I know how to add a new row using:

items is a string array of the column data…
list_view.Items.Add( new ListViewItem( items ) );

But I have no idea how to update the content of a particular row. Please help.

Thank you!

This code updates the second SubItem of a ListViewItem.


ListViewItem item = new ListViewItem();
item = this.list_view.SelectedItems[0];
item.SubItems[1].Text = "000";

What I am basically doing is getting the first selected item in the listview (this.list_view.SelectedItems[0]). If you have multiselect turned on, you will have to loop through the SelectedItems collection and make your changes as usual. After getting the selected item, I am changing the value of the second SubItem to 000.