locked
Delete all selected items in listbox? RRS feed

  • Question

  • How can I delete all the selected items in a multi-select listbox in VB.NET?

    Thanks,

    James

    Saturday, November 25, 2006 2:39 AM

Answers

  • just go through the selecteditems and remove it from the listbox items collection, but in reverse...like so:

    For counter As Integer = Me.ListBox1.SelectedItems.Count - 1 To 0 Step -1

    Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItems.Item(counter))

    Next

    Saturday, November 25, 2006 2:59 AM

All replies

  • just go through the selecteditems and remove it from the listbox items collection, but in reverse...like so:

    For counter As Integer = Me.ListBox1.SelectedItems.Count - 1 To 0 Step -1

    Me.ListBox1.Items.Remove(Me.ListBox1.SelectedItems.Item(counter))

    Next

    Saturday, November 25, 2006 2:59 AM
  • Wow I hadn't thought of doing it in reverse

    Thanks!

    P.S. Whew I've lost count of how many of my problems you've fixed, ahmedilyas!

    Saturday, November 25, 2006 3:05 AM
  • hehe no worries buddy ;-) always a pleasure
    Saturday, November 25, 2006 3:35 AM
  • me.listbox.items.clear did it for me.

    Wednesday, February 29, 2012 7:40 PM