Results 1 to 11 of 11

Thread: Listbox.removeItem(Indexes() as Integer)?

  1. #1

    Thread Starter
    Lively Member norden's Avatar
    Join Date
    Jun 2003
    Posts
    108

    Listbox.removeItem(Indexes() as Integer)?

    Hi, anybody knows how to remove selected items from a lisbox w/out looping through the list?
    Last edited by norden; Jul 4th, 2003 at 09:41 AM.

  2. #2
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    try this

    VB Code:
    1. For i = 0 To List1.SelCount - 1
    2.         List1.RemoveItem (List1.ListIndex)
    3.     Next i

    it's a loop, but not through the whole list
    Anticipation of death is worse than death itself

  3. #3

    Thread Starter
    Lively Member norden's Avatar
    Join Date
    Jun 2003
    Posts
    108
    Walter... You're the man!!! Thanks.

  4. #4
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    thankyou, anytime
    Anticipation of death is worse than death itself

  5. #5

    Thread Starter
    Lively Member norden's Avatar
    Join Date
    Jun 2003
    Posts
    108
    Whoops! It's removing the wrong item from my list.

  6. #6
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589
    ListIndex would give you the index of the selected item.. It should work. Dont put it in the Loop
    Just say
    VB Code:
    1. With List1
    2.      .RemoveItem(.ListIndex)
    3. End With

  7. #7
    Lively Member
    Join Date
    Aug 2002
    Location
    England
    Posts
    84
    Originally posted by sridharavijay
    ListIndex would give you the index of the selected item.. It should work. Dont put it in the Loop
    Just say
    VB Code:
    1. With List1
    2.      .RemoveItem(.ListIndex)
    3. End With
    that would only remove the one selected. norden wants to remove all the currently selected (multiple selections)
    Anticipation of death is worse than death itself

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The only way to remove multiple items would be to use a loop and the loop must traverse the list in reverse order.

    VB Code:
    1. Dim lngItem as Long
    2.  
    3. If List1.SelCount > 0 Then
    4.  
    5.    For lngItem = List1.ListCount - 1 to 0 Step -1
    6.          If List1.Selected(lngItem) Then
    7.               List1.RemoveItem lngItem
    8.          End If
    9.    Next
    10.  
    11. End If

    Just curious, why don't you want/can't use a loop?

  9. #9

    Thread Starter
    Lively Member norden's Avatar
    Join Date
    Jun 2003
    Posts
    108
    Originally posted by brucevde
    Just curious, why don't you want/can't use a loop?
    I have got a long list, and removing items is too slow and my window is flickering
    as I go through the list.

    Reverse loop is a neat way of doing it, thanks.

  10. #10
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    If the control / form is flickering, you could set the control (listbox etc.) to visible = false while you are doing the updates.

    Or, it would be better to use:
    VB Code:
    1. Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long
    2.  
    3. Private Sub LoadData()
    4.    Screen.MousePointer = vbHourGlass
    5.    LockWindowUpdate MyGrid.hWnd
    6.  
    7.    'Code here to populate / remove
    8.    
    9.    LockWindowUpdate False
    10.    Screen.MousePointer = vbDefault
    11. End Sub

  11. #11

    Thread Starter
    Lively Member norden's Avatar
    Join Date
    Jun 2003
    Posts
    108
    Yes, I set the visible property to false and put label control in the background that says "Pls Wait..."

    Thank's guys...

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