Guest kanenas Posted May 31, 2002 Posted May 31, 2002 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? Quote
Guest kanenas Posted May 31, 2002 Posted May 31, 2002 I forgot to tell that this only happens when I haven't select any items Quote
*Gurus* divil Posted May 31, 2002 *Gurus* Posted May 31, 2002 Of course you cannot remove a selected item if there aren't any. Try wrapping that statement in a Try...Catch block. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest kanenas Posted May 31, 2002 Posted May 31, 2002 I would appreciate it if you were more specific because I'm new and quite confused. I don't know how this Try...Catch works! Quote
NicoVB Posted June 1, 2002 Posted June 1, 2002 Try lst1.Items.Remove(lst1.SelectedItems(0)) Catch ex1 as Exeption Msgbox(ex1.Description) End Try Quote Visit http://www.nico.gotdns.com Now ONLINE!
Guest kanenas Posted June 1, 2002 Posted June 1, 2002 Thanx for the help! It worked but Msgbox(ex1.Description) was unnecessary. At least it worked without it! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.