-
delete listview item
I use this code to remove the item in a ListView.
Dim lvi As ListViewItem = DirectCast(ListView1.Items(1), ListViewItem) '/// where (1) is the index of the item
ListView1.Items.Remove(lvi)
But if there's only one item in the listview, I encounter an error.
What code should I write?
-
the indexes of a listview in vb.net start at zero , so if you only have one item in the listview it will error on ListView1.Items(1) , because there isn't an item with an index of 1. you would need to specify 0 for the first item