|
-
Oct 22nd, 2007, 01:18 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Listview Remove Item when unchecked
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.
-
Oct 22nd, 2007, 01:58 AM
#2
Re: Listview Remove Item when unchecked
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
Last edited by Fazi; Oct 22nd, 2007 at 02:09 AM.
-
Oct 22nd, 2007, 02:11 AM
#3
Thread Starter
PowerPoster
Re: Listview Remove Item when unchecked
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
-
Oct 22nd, 2007, 02:17 AM
#4
Re: Listview Remove Item when unchecked
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.
-
Oct 22nd, 2007, 02:19 AM
#5
Re: Listview Remove Item when unchecked
Leinad31, what about my example. will that method ok?
-
Oct 22nd, 2007, 02:33 AM
#6
Re: Listview Remove Item when unchecked
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)
-
Oct 22nd, 2007, 02:36 AM
#7
Thread Starter
PowerPoster
Re: Listview Remove Item when unchecked
-
Oct 22nd, 2007, 02:54 AM
#8
Re: Listview Remove Item when unchecked
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
Last edited by Fazi; Oct 22nd, 2007 at 02:57 AM.
-
Oct 22nd, 2007, 03:14 AM
#9
Thread Starter
PowerPoster
Re: Listview Remove Item when unchecked
Seems that I was on the right track, but not there. Thank you both for the solution. Easier then expected.
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
|