Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21301

Listbox item removed but item List text stays visible

$
0
0
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:

Code:

Index  Text  ItemData
  0      1      1
  1      2      2
  2      3      3
  3      4      4
  4      5      5

Now I remove item 2 or the entry that says "3". Now the listbox now looks like this:

Code:

Index  Text  ItemData
  0      1      1
  1      2      2
  2      4      4
  3      5      5

OK, so far.

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

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

Code:

For n = 0 To List1.ListCount - 1
  If List1.ItemData(n) = NumberToRemove
    List1.RemoveItem n
    Exit For
  End If
 Next n

So, item 0 was removed from the listbox. Now the listbox looks like this:

Code:

Index  Text  ItemData
  0      2      2
  1      4      4
  2      5      5
  3      3      3

Now NumberToRemove contains the value 2 and the listbox looks like this:

Code:

Index  Text  ItemData
  0      4      4
  1      5      5
  2      3      3

Now NumberToRemove contains the value 4 and the listbox looks like this:

Code:

Index  Text  ItemData
  0      5      5
  1      3      3

Next NumberToRemove contains the value 5 and the listbox looks like this:

Code:

Index  Text  ItemData
  0      3      3

And last, NumberToRemove contains the value 3 and the listbox looks like this:

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

Viewing all articles
Browse latest Browse all 21301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>