简体   繁体   中英

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 . 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. But in case myListView already has some SelectedItems , and I want to add more, I cannot use ListView.SetSelectedItems() .

How can I add selected items more effectively? Is there an AddRange() function or a similar method?

Is there an AddRange() function or a similar method?

No.

The SelectedItems property of a ListView returns an instance of the internal type SelectedItemCollection and this one has no AddRange() method.

But even it there actually was an AddRange() method, what do you think it would do? It would certainly loop over the IEnumerable that you pass to it somehow.

There is no more efficient way of iterating through items.

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