Home > DeveloperSection > Forums > Transferring data from one list box to another c#
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    December-12-2013 1:58 AM

 C# C# 
Ratings:


 1 Reply(s)
 947  View(s)
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?



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-12-2013 2:28 AM

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;

    }

}


Don't want to miss updates? Please click the below button!

Follow MindStick