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
2009-03-23 08:23:13
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
2009-03-23 08:27:57
A:
ListViewItem listItemToMove = listView1.SelectedItems[0];
ListViewItem itemToAdd = (ListViewItem)listItemToMove.Clone ();
listView2.Items.Add (itemToAdd);
listView1.Items.Remove(listItemToMove);
Frederik Gheysels
2009-03-23 08:25:06
+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
2009-03-23 08:26:57
Moving requires you to remove the item out of the first listview as well. :) (which will not work inside a foreach loop).
Frederik Gheysels
2009-03-23 09:00:23