I have a ListView and a collection of ListViewItem. I simply want to insert all items in the collection at the top of the ListView.
Currently, I am doing it this way:
CollectionOfListViewItems.Sort(New CustomComparer(SortOrder.Descending)) For Each lvi As ListViewItem In CollectionOfListViewItems TargetListView.Items.Insert(0, lvi) Next
Since every insert operation will shift all items in the ListView, each insert operation will take O(n) time which seems like a bit of a waste.
Is there a better way of going about the same? Note that I know about
InsertRange() but unfortunately, that method is not available for the collection
Leave an answer