Hi, anybody knows how to remove selected items from a lisbox w/out looping through the list?
Printable View
Hi, anybody knows how to remove selected items from a lisbox w/out looping through the list?
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
Walter... You're the man!!! Thanks.
thankyou, anytime :)
Whoops! It's removing the wrong item from my list. :D
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)Quote:
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
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?
I have got a long list, and removing items is too slow and my window is flickeringQuote:
Originally posted by brucevde
Just curious, why don't you want/can't use a loop?
as I go through the list.
Reverse loop is a neat way of doing it, thanks.
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
Yes, I set the visible property to false and put label control in the background that says "Pls Wait...":D
Thank's guys...