How can I copy selected items from one listview to another on button click..?? without any redundancy also can I give the option for multiple selection of items and adding them in a bulk without using the ctrl from keyboard?? making it user friendly can we use checkboxes and how will they work??
The code below is used to copy the entries for the single selection of the item and also it gives the duplicate entries on selecting that item again…please help me out to remove the flaws…
private void btn_Add_Click(object sender, EventArgs e)
{
CopySelectedItems(source_name, target_name);
}
private void CopySelectedItems(ListView source, ListView target)
{
foreach (ListViewItem item in source.SelectedItems) {
target.Items.Add((ListViewItem)item.Clone());
}
}
There are a couple of different ways.
If you want to copy the items from a to b:
If you want to move the items from a to b:
Update
You mention that you want to preserve the order in which the items are located in the source
ListViewcontrol. I assume that they appear there in some sorted order? If so, you can create a function that uses the same sorting rule to figure out where to insert an item in the targetListView(my example uses the value in the second column:It’s hard to give a more exact answer without knowing more details.