Results 1 to 4 of 4

Thread: ListBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Cairns,North Queensland, Australia
    Posts
    21
    I have two listboxes List1 has the numbers from 11 to 99. List2 can hold any of these numbers depending on the user.
    My Question is, how can I remove the numbers in list2 from List1 with a commandbutton.

    Thanks for your help. Andyb

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    ???

    Code:
    Private Sub Command1_Click()
    List1.RemoveItem 5 'the 6th item in the listbox
    List1.RemoveItem 5 'the 6th item in the listbox
    End Sub
    ??? Don't know what ya want!?!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Location
    Cairns,North Queensland, Australia
    Posts
    21
    I want to remove all the items in list2 from list1.

  4. #4
    Guest
    Try the following.
    Code:
    Private Sub Command1_Click()
        For I = 0 To List2.ListCount - 1
            For X = 0 To List1.ListCount - 1
                If List2.List(I) = List1.List(X) Then List1.RemoveItem (X)
            Next X
        Next I
    End Sub
    
    Private Sub Form_Load()
        'Populate List1 with 20 items
        For I = 0 To 20
            List1.AddItem I
        Next I
        
        'Populate List2 with 10 items
        For I = 0 To 10
            List2.AddItem I
        Next I
    End Sub

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