.NET Listview Copy Items
Is there a way to copy the entire contents of a listview from one control to another, without manually setting up the second one and开发者_如何学Go iterating through each item? I'm thinking something like:
ListView myNewListView = new ListView();
lvwExistingView.CopyTo(myNewListView);
Or even:
ListView myNewListView = new ListView();
lvwExistingView.Items.CopyTo(myNewListView.Items, 1); // This doesn't work because it expects an array
A ListViewItem
can't exist on more than one list view at one time. They need to be recreated.
But you can use LINQ to make this quick.
myNewListView.Items.AddRange(
lvwExistingView.Items.Cast<ListViewItem>().Select(i =>
i.Clone()).Cast<ListViewItem>().ToArray());
精彩评论