|
-
Jul 4th, 2003, 08:38 AM
#1
Thread Starter
Lively Member
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.
-
Jul 4th, 2003, 08:59 AM
#2
Lively Member
try this 
VB Code:
For i = 0 To List1.SelCount - 1
List1.RemoveItem (List1.ListIndex)
Next i
it's a loop, but not through the whole list
Anticipation of death is worse than death itself
-
Jul 4th, 2003, 09:08 AM
#3
Thread Starter
Lively Member
Walter... You're the man!!! Thanks.
-
Jul 4th, 2003, 09:10 AM
#4
Lively Member
thankyou, anytime
Anticipation of death is worse than death itself
-
Jul 4th, 2003, 09:40 AM
#5
Thread Starter
Lively Member
Whoops! It's removing the wrong item from my list.
-
Jul 4th, 2003, 09:57 AM
#6
Fanatic Member
ListIndex would give you the index of the selected item.. It should work. Dont put it in the Loop
Just say
VB Code:
With List1
.RemoveItem(.ListIndex)
End With
-
Jul 4th, 2003, 09:58 AM
#7
Lively Member
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:
With List1
.RemoveItem(.ListIndex)
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
-
Jul 4th, 2003, 10:09 AM
#8
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:
Dim lngItem as Long
If List1.SelCount > 0 Then
For lngItem = List1.ListCount - 1 to 0 Step -1
If List1.Selected(lngItem) Then
List1.RemoveItem lngItem
End If
Next
End If
Just curious, why don't you want/can't use a loop?
-
Jul 4th, 2003, 10:20 AM
#9
Thread Starter
Lively Member
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.
-
Jul 4th, 2003, 10:25 AM
#10
Frenzied Member
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:
Private Declare Function LockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Long) As Long
Private Sub LoadData()
Screen.MousePointer = vbHourGlass
LockWindowUpdate MyGrid.hWnd
'Code here to populate / remove
LockWindowUpdate False
Screen.MousePointer = vbDefault
End Sub
-
Jul 4th, 2003, 10:29 AM
#11
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|