简体   繁体   English

如何有效地实现WPF ListView SelectedItems的AddRange()?

[英]How to effectly implement AddRange() for a WPF ListView SelectedItems?

I have a ListView and I wanted to add some new items to its ListView.SelectedItems . 我有一个ListView ,我想向其ListView.SelectedItems添加一些新项目。 I was using a slow approach: 我使用的是缓慢的方法:

for (int i = beginIndex; i <= endIndex; i++)
{
    myListView.SelectedItems.Add(myObjectList[i]);
}

If myListView is empty before add, I could use this answer to add selected items. 如果myListView在添加之前为空,则可以使用此答案添加所选项目。 But in case myListView already has some SelectedItems , and I want to add more, I cannot use ListView.SetSelectedItems() . 但是如果myListView已经有一些SelectedItems ,而我想添加更多,则不能使用ListView.SetSelectedItems()

How can I add selected items more effectively? 如何更有效地添加所选项目? Is there an AddRange() function or a similar method? 是否有AddRange()函数或类似的方法?

Is there an AddRange() function or a similar method? 是否有AddRange()函数或类似的方法?

No. 没有。

The SelectedItems property of a ListView returns an instance of the internal type SelectedItemCollection and this one has no AddRange() method. ListViewSelectedItems属性返回内部类型SelectedItemCollection的实例,并且该实例没有AddRange()方法。

But even it there actually was an AddRange() method, what do you think it would do? 但是,即使实际上有一个AddRange()方法,您认为它会做什么? It would certainly loop over the IEnumerable that you pass to it somehow. 它肯定会遍历您以某种方式传递给它的IEnumerable

There is no more efficient way of iterating through items. 没有更有效的方式遍历项目。

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

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