Moving Selected Data From Listbox1 to Listbox2

Posted on 2012-09-19
Last Modified: 2012-09-19
Hello Experts,

I want to move some of the results of a query displayed in Listbox1 to Listbox2. I'm only wanting the SELECTED items from Listbox1 (a multiselect listbox) to go to Listbox2.

The code I'm using is putting the correct number of rows but inserting "System.Data.DataRowView" instead of the actual text from Listbox1. Usually I use SelectedValue when dealing with query results but that fails also. I've also tried SelectedIndices but that was a failure too. I've also added .ToString but that failed as well.

Here's my code:

 Dim i As Integer
        For i = 0 To Listbox1.SelectedItems.Count - 1
        Next i

Any help would be appreciated,

Question by:JackW9653
    LVL 13

    Accepted Solution

    Give this a try:

     Dim i As Integer
            For i = 0 To Listbox1.SelectedItems.Count - 1
               Dim myRv as DataRowView=Listbox1.SelectedItems.Item(i)
               Listbox2.Items.Add(myRv(0).ToString()) ' -->> Adjust for the column you want
            Next i
    LVL 13

    Expert Comment

    If you can't do an implicit conversion, try a direct cast.

    Dim i As Integer
            For i = 0 To Listbox1.SelectedItems.Count - 1
               Dim myRv as DataRowView=DirectCast(Listbox1.SelectedItems.Item(i), DataRowView)
               Listbox2.Items.Add(myRv(0).ToString()) ' -->> Adjust for the column you want
            Next i

    Author Closing Comment

    Thank you very much, it worked perfectly.


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now