Results 1 to 7 of 7

Thread: Listbox problematic

  1. #1

    Thread Starter
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049

    Unhappy

    I can't figure it out anymore
    --

    My prob:
    The user can add files to a listbox to let 'm run in the program (in a batch-sequence) but ofcourse I have to let the user delete files he doesn't need to be parsed.

    but....

    when I try to delete a item in a selected() way it gives me an error..

    --

    If lList.ListCount = 1 Then
    lList.RemoveItem (lList.ListIndex)
    Else
    For I = 0 To (lList.ListCount)
    If lList.Selected(I) = True Then
    lList.RemoveItem (I)
    End If
    Next I
    End If

    Most of the time if I = 2 then it crashes...
    What am I doin' wrong here?

    Thnx in advance;

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    the items are indexed so that the 0 counts and the last one is lListcount -1
    Code:
    For I = 0 To (lList.ListCount) -1
      If lList.Selected(I) = True Then 
        lList.RemoveItem (I) 
      End If 
    Next I
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049
    Tried... Crashed.

    I solved it in a very cruel way though
    --
    On Error Resume Next
    lList.ListIndex = -1
    For I = -1 To (lList.ListCount - 1)
    If lList.Selected(I) = True Then lList.RemoveItem I
    Next I
    I = 0
    If lList.Selected(I) = True Then lList.RemoveItem I
    On Error GoTo 0
    --

    It crashes on the Selected(I) (I is that at that point 0).. so I presume it crashes because the list index is updated at that point and that the Index says there is a 2 but it's now 1 or 0

    (removing more then one option)

    Did that make sense?

  4. #4
    Guest

    Other code?

    What other Subs you have that might affect when item is selected or something?

    If there's any, you should do somehow so that nothing else wouldn't be checked when deleting items.

    Hope this helps,

  5. #5

    Thread Starter
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049
    Nothing interferes with the list box except the sub mentioned above.


  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    The way to remove multiple items from a listbox is to loop backwards thru the listbox - otherwise, your loop counter will get out of sync with the listindexes and cause you the problems that you describe.

    Try this:
    Code:
    For I = (lList.ListCount -1) To 0 Step -1
      If lList.Selected(I) = True Then 
        lList.RemoveItem (I) 
      End If 
    Next I
    "It's cold gin time again ..."

    Check out my website here.

  7. #7

    Thread Starter
    Frenzied Member Devion's Avatar
    Join Date
    Sep 2000
    Location
    The Netherlands
    Posts
    1,049
    That should do the trick; Thank you.

Posting Permissions

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



Click Here to Expand Forum to Full Width