0
Thanks for the help it worked
0
Take a look at this line.
ListViewItem item = listView1.SelectedItems[0];
ListView.SelectedItems is a property that returns a ListViewItemCollection. If no items are selected, the collection is empty. Like any empty array with zero values in it, an exception will be thrown when you try to get the first value when it doesn't exist.
To fix this problem, you'll need to insert an if statement.
...
ListViewItem item;
if (listView1.SelectedItems.Count > 0) item = listView1.SelectedItems[0];
...