Remove a line from a ListView

  • Thread starter Thread starter kanenas
  • Start date Start date
K

kanenas

Guest
Hi!

I have a listview and I want to make a button to remove any unwanted
entries. I tried

If Not lst1.SelectedItems Is Nothing Then
lst1.Items.Remove(lst1.SelectedItems(0))
End If

But I got an error in the second line
Any ideas?
 
Of course you cannot remove a selected item if there arent any. Try wrapping that statement in a Try...Catch block.
 
I would appreciate it if you were more specific because Im new and quite confused. I dont know how this Try...Catch works!
 
Code:
Try 
lst1.Items.Remove(lst1.SelectedItems(0)) 
Catch ex1 as Exeption
Msgbox(ex1.Description)
End Try
 
Thanx for the help! It worked but
Msgbox(ex1.Description)
was unnecessary. At least it worked without it!
 
Back
Top