简体   繁体   中英

How to cut, copy, paste any listview item in C#?

 for (int i = 0; i < listView1.Items.Count; i++)
 {
     if (listView1.Items[i].Selected)
     {
         listView1.Items[i].Remove();
     }
 }

This function simply deletes the selected item in listview.. but i want to cut it and paste it somewhere else.

It sounds like you want to remove the selected listitems and move them to another listview.

ListView sourceListView = new ListView();
ListView destListView = new ListView();

var selected = sourceListView.Items
                              .Cast<ListViewItem>()
                              .Where(x => x.Selected)
                              .ToList();

foreach (var item in selected)
{
    sourceListView.Items.Remove(item);
    destListView.Items.Add(item);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM