tags:

views:

810

answers:

3

How to move data from one listview to another using c#

+1  A: 

homework?

Foreach (object o in listbox1.Items)
{
Listbox2.Items.Add(o)
}
PoweRoy
The question is about ListView; I don't know by heart for ListBox, but for a ListView, you cannot add the same item to 2 different listviews.
Frederik Gheysels
A: 
ListViewItem listItemToMove = listView1.SelectedItems[0];
ListViewItem itemToAdd = (ListViewItem)listItemToMove.Clone ();
listView2.Items.Add (itemToAdd);
listView1.Items.Remove(listItemToMove);
Frederik Gheysels
+1  A: 
ListViewItem itemClone;
ListView.ListViewItemCollection coll = listView1.Items;
foreach (ListViewItem item in coll)
{
itemClone = item.Clone() as ListViewItem;
listView1.Items.Remove(item);
listView2.Items.Add(itemClone);
}
Anuraj
Moving requires you to remove the item out of the first listview as well. :) (which will not work inside a foreach loop).
Frederik Gheysels
Sorry. I updated the code.
Anuraj