A listbox contains 5 items. The text of each item is "1", "2", "3", "4", and "5" Also each entry has it's ItemData with the same values; ie, 1 ,2, 3, 4, 5. So, the listbox looks like this:
Now I remove item 2 or the entry that says "3". Now the listbox now looks like this:
OK, so far.
Now I add that removed item back again. So now the listbox looks like this:
OK, so far
Now I start removing each entry from the listbox using this code:
The loop is executed each time the variable NumberToRemove changes.
The 1st time, NumberToRemove, contains the value 1
So, item 0 was removed from the listbox. Now the listbox looks like this:
Now NumberToRemove contains the value 2 and the listbox looks like this:
Now NumberToRemove contains the value 4 and the listbox looks like this:
Next NumberToRemove contains the value 5 and the listbox looks like this:
And last, NumberToRemove contains the value 3 and the listbox looks like this:
When I single step through the loop on this last time I see that
List1.RemoveItem n is executed and n = 0 but the item text, "3" remains visible in the listbox although the listbox's ListCount is 0
Code:
Index Text ItemData
0 1 1
1 2 2
2 3 3
3 4 4
4 5 5
Code:
Index Text ItemData
0 1 1
1 2 2
2 4 4
3 5 5
Now I add that removed item back again. So now the listbox looks like this:
Code:
Index Text ItemData
0 1 1
1 2 2
2 4 4
3 5 5
4 3 3
Now I start removing each entry from the listbox using this code:
The loop is executed each time the variable NumberToRemove changes.
The 1st time, NumberToRemove, contains the value 1
Code:
For n = 0 To List1.ListCount - 1
If List1.ItemData(n) = NumberToRemove
List1.RemoveItem n
Exit For
End If
Next n
Code:
Index Text ItemData
0 2 2
1 4 4
2 5 5
3 3 3
Code:
Index Text ItemData
0 4 4
1 5 5
2 3 3
Code:
Index Text ItemData
0 5 5
1 3 3
Code:
Index Text ItemData
0 3 3
Code:
Index Text ItemData
0 3 3
When I single step through the loop on this last time I see that
List1.RemoveItem n is executed and n = 0 but the item text, "3" remains visible in the listbox although the listbox's ListCount is 0