VISUAL BASIC PROBLEM |
|||||||||||||||||||||||
Problem Code | VBPBLST001 | ||||||||||||||||||||||
Description |
How To remove multiple item from THE LISTBOX. |
||||||||||||||||||||||
VB Version Compatibility |
This solution is tested in VB6 and expected to work in VB5 and VB4. |
||||||||||||||||||||||
Theory |
LISTBOX Custom Control provides REMOVEITEM method to delete item from it. It takes position of item as an argument and remove it from the LISTBOX. Since this method remove one item at a time therefor in order to remove more that one item we need to use REMOVEITEM method inside the loop. |
||||||||||||||||||||||
Solution |
Note Key to this problem is using Loop in descending order. because if you use Loop from 0 to list1.listcount - 1, it would generate runtime error because after deleting every item from the LISTBOX all items are re-numbered. e.g, if you want to remove 3rd and 4th item from LISTBOX and if you put loop from 0 to list1.listcount -1 then after removing 3rd item from the LISTBOX 4th item become 3rd item and when Loop reaches to the 4th item it would not found the 4th item and generate error. |
--------------------X-X-X-X-X-X-X-X--------------------
SPECIAL NOTE :- ALTHOUGH this is tip is tested thoroughly. Using this tip is at user own risk. Visual Code is not responsible for any damage caused directly or indirectly. |