Results 1 to 3 of 3

Thread: Using Listboxes to move names

  1. #1
    Guest

    Post

    I have been trying to move a list of names 1 at a time or the whole names at a go from a "listbox1" to a "Listbox2" both on the same form. This should happen whenever I click on 2 command buttons at different times. The first and second buttons have "Add" and "Add All" written on them. Any help would be much appreciated.

    Thanks

    Albert

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Post

    Try this for moving one item (the one that is selected):

    Private Sub cmdAdd_Click()
    List2.Add List1.List(List1.ListIndex)
    List1.Remove List1.ListIndex
    End Sub

    And to move them all:

    Private Sub cmdAddAll()
    Dim i As Integer
    For i = List1.ListCount - 1 To 0 Step -1
    List2.Add List1.List(i), 0
    List1.Remove i
    Next
    End Sub

    Good luck!

    ------------------
    Joacim Andersson
    [email protected]
    [email protected]
    www.YellowBlazer.com



  3. #3
    Lively Member
    Join Date
    Nov 1999
    Posts
    64

    Post

    This should work:

    For the add one button:

    Private Sub Command1_Click()
    List2.AddItem List1
    End Sub

    For the add all button:

    Private Sub Command2_Click()

    For n = 1 To List1.ListCount
    List1.ListIndex = n - 1
    List2.AddItem List1
    Next n
    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