moving data from one ListBox to Another ListBox


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: moving data from one ListBox to Another ListBox

  1. #1
    Join Date
    Jul 2008
    Posts
    3

    moving data from one ListBox to Another ListBox

    I am using the code posted by Kerry which adds all the Items from ListBox2 to ListBox1. Is there any way to add one selected item at a time from ListBox2 to ListBox1 and remove the items added to ListBox1 from ListBox2??

    Below is the code used by me:

    Me.ListBox1.DisplayMember = Me.ListBox2.DisplayMember
    Me.ListBox1.ValueMember = Me.ListBox2.ValueMember

    For Each item In Me.ListBox2.Items
    Me.ListBox1.Items.Add(item)
    Next

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Code:
    'move all items
    Dim i As Long
       For i = 0 To List1.ListCount - 1
           List2.AddItem List1.List(i)
       Next
       List1.Clear
    
    'move selected items
    
    Dim i As Long
    For i = List2.ListCount - 1 To 0 Step -1 ' counts list entries
        If List2.Selected(i) = True Then ' if selected then
            List1.AddItem List2.List(i) ' add to other list
            List2.RemoveItem i ' optional remove
        End If
    Next

Similar Threads

  1. How Vietnam Can Still Be Won
    By Steven Hughes in forum Architecture and Design
    Replies: 0
    Last Post: 02-19-2008, 08:07 AM
  2. Replies: 6
    Last Post: 01-22-2008, 10:19 AM
  3. Moving data between sources
    By Russell Nash in forum .NET
    Replies: 0
    Last Post: 01-13-2006, 09:20 AM
  4. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 11:53 AM
  5. Complex Data Consumer Data Aware Classes
    By Desmond Cassidy in forum authorevents.kurata
    Replies: 3
    Last Post: 04-19-2000, 04:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center