-
Im using listbox (style "Checked")[BR]
How can I remove items from the list? I need to remove the checked items from the list.[BR]
I have a command button in the form. What code do I need to enter to the command button so that it removes the selected item(s) from the list?[BR]
Thank you!
-
The easiest way may be to clear the list box and reenter the list with just those items.
listbox.clear I believe will clear it.
If you know the items, then just put em back in if they get loaded from something else then before clearing:
dim strItems() as string, intI as integer
dim intItems as integer
intItems = listbox.listcount
redim strItems(intItems)
for inti = 1 to intItems
stritems(inti) = listbox.ItemData(inti)
next inti
'now you have all the items, you could put if statement in the loop to skip certain items.
dim intJ as integer
redim strItems(intItems - number of items you are removing)
intJ = 1
for inti = 1 to intItems
if listbox.itemdata(inti) <> "Cleared item" then
stritems(intj) = listbox.ItemData(inti)
intJ = intJ +1
end if
next inti
Hope this helps.
-
:eek: :eek: :eek: :eek: :eek: :eek: :eek: :eek:
Personally, I would do it this way:
Code:
Private Sub cmdRemoveSeletedItems_Click()
Dim i As Integer
For i = List1.listCount - 1 To 0 Step -1
If List1.Selected(i) Then
List1.RemoveItem (i)
End If
Next i
End Sub
------------------
Mark Sreeves
Analyst Programmer
[email protected]
A BMW Group Company
-
This code will check all your items in the list and remove only the ones that are selected.
Code:
Dim i As Integer
Dim intMaxItems As Integer
intMaxItems = List1.ListCount - 1
i = 0
Do While i <= intMaxItems
MsgBox List1.List(i)
If List1.Selected(i) = True Then
List1.RemoveItem i
intMaxItems = intMaxItems - 1
Else
i = i + 1
End If
Loop