TRANSFERRING DATA FROM ONE LIST BOX TO ANOTHER C#

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
C# 
C#
 1332  View(s)
Ratings:
Rate this:

I have 2 list boxes one is connected to a database the other isnt.

I want to be able to send the selected item from the listbox connected to the database to the one that isnt.

Ive written this code

listBox2.Items.Add(listBox1.SelectedItem);

But instead of copyin the item i get "

System.Data.DataRowView

Anyone having any advice?

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: Transferring data from one list box to another c#

    Hi Jeet,

    This is the simplest way to load a listbox to another list box and at the same time remove the data from the sorce listbox

    int mCount = ListBox1.Items.Count;

    for (int i = 0; i <= mCount - 1; i++)

    {

        if (ListBox1.Items[i] == ListBox1.SelectedItem)

        {

            ListBox2.Items.Add(ListBox1.SelectedItem);

            ListBox1.Items.Remove(ListBox1.SelectedItem);

            mCount=mCount - 1;

            i=i - 1;

        }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!