Results 1 to 4 of 4
  1. #1
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Listbox Item Delete (XP)

    If you loop backwards, you must also reverse the loop limits. Try this:

    Dim x As Long
    For x = ListBox2.ListCount - 1 To 0 Step -1
    If ListBox2.Selected(x) Then
    ListBox2.RemoveItem x
    End If
    Next i

  2. #2
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox Item Delete (XP)

    Hans,

    It works. I'd pat you on the back but that would be a stretch (California to Leiden) <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15>

    Thanks again.
    John

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Listbox Item Delete (XP)

    I have a listbox with a property of multiselect and a button to control the deletion of the items. I would like to delete those items which are highlighted but encounter issues with the index of the listbox.

    The code attached to the button is:
    For x = 0 To ListBox2.ListCount - 1 Step -1
    If ListBox2.Selected(x) = True Then ListBox2.RemoveItem (x)
    Next x

    I put the Step -1 in the first line of code thinking that deleting from the bottom up would resolve the index issue but to no avail.

    Any suggestions would be appreciated,
    John

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Listbox Item Delete (XP)

    I stumbled across this snipet of code but still have issues with multiselect items:

    If Listbox2.ListIndex <> -1 Then
    Dim x As Integer
    x = Listbox2.ListIndex
    Listbox2.RemoveItem x
    End if


    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •