Results 1 to 3 of 3

Thread: VB6- ListBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Location
    Karhula, Finland
    Posts
    4

    Post

    How can I remove Items from the list box? It should work like this:
    (My list boxes style is checkbox) I select one or more of them and then click the remove button. What code do I need to remove the selected item?

    Thank you!

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Location
    Springfield, IL
    Posts
    124

    Post

    This code should work in removing the checked items:
    Code:
        Dim i As Integer
        Dim intMaxItems As Integer
        
        i = 0
        intMaxItems = List1.ListCount - 1
        Do While i <= intMaxItems
            If List1.Selected(i) = True Then
                List1.RemoveItem i
                intMaxItems = intMaxItems - 1
            Else
                i = i + 1
            End If
        Loop

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    You can do it a little easier by going backward through the list
    Code:
        Dim i As Integer
        
        For i = List1.ListCount - 1 To 0 Step -1
            If List1.Selected(i) = True Then
                List1.RemoveItem i
            End If
        Next
    ------------------
    Marty
    HASTE CUISINE
    Fast French food.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width