Hi,
Ho do I remove an item from the listview when I gets unchecked? I can't use the SelectedItem, 'cause that isn't always the case. Just the Checked=False.
Thanks for the reply in advance.
Printable View
Hi,
Ho do I remove an item from the listview when I gets unchecked? I can't use the SelectedItem, 'cause that isn't always the case. Just the Checked=False.
Thanks for the reply in advance.
Loop through all the items and if an item has unchecked, remove that item and reload the the list.
Code:Private Sub Command1_Click()
For n = 1 To lv.ListItems.Count
If lv.ListItems(n).Checked = False Then
'note the (n) item
Next n
'Reload every thing with out (n) item
End Sub
hmmm... Tried that, but I'm doing something wong there...
Code:Private Sub ListView4_ItemCheck(ByVal Item As MSComctlLib.ListItem)
For i = 1 To ListView4.ListItems.Count
If Item(i).Checked = False Then
ListView4.ListItems.Remove (i)
End If
End Sub
When iterating for deletion using For loops, do so in reverse order; from Count to 1. This is because the upper bound supplied to the For loop construct becomes obsolete once an item is removed.
Leinad31, what about my example. will that method ok?
Yes, but if the number of items to be removed is small then its easier and faster to go ahead with the removal thru reverse iteration (less intermediate data structure maintenance)
Example?
Radjes, what leinad telling is ...
Code:Private Sub Command1_Click()
For n = lv.ListItems.Count to 1 step -1
If lv.ListItems(n).Checked = False Then
lv.ListItems.remove(n)
End if
Next n
End Sub
Seems that I was on the right track, but not there. Thank you both for the solution. Easier then expected.