简体   繁体   English

如何在C#中剪切,复制,粘贴任何列表视图项?

[英]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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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