DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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,652
    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
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links