is it possible to get the text values of specific column in a listview in form of array without using a loop function? lets say I have a listview contains 2 columns and 5000 records. what I want is to get all the texts under column 2 only but without using a loop. I know I can accomplish this with a loop but it takes ages if I had 5000+ records..
any ideas?
I feel your pain and I’ve personally experienced how slow a
ListViewItemsCollectioncan be.You can access the second column of a
ListViewwithout a for loop like this:but this isn’t any faster than a for loop. In fact it’s a little bit slower! Other tricks like trying to use
ListViewItemsCollection.CopyToalso fail miserably.A major problem with the
ListViewis that is pathologically slow when used as a data structure. The propertyListView.Itemslooks like a data structure and you can use it like a data structure but any way you slice it:So if you follow alexD’s advice you will find that a real data structure will outperform a
ListViewItemCollectionby orders of magnitude. The moral of the story is if you want to query the data in aListViewItemCollectionfast, you have no alternative than to keep a fast copy outside of theListView. Practically any data structure will do, e.g.string[][]string[,]List<List<string>>List<string[]>or evenList<Tuple<string, string>>.These can all store the same data as a two-column
ListViewand will be instantaneously fast by comparison to using theListViewas a data structure. It is inconvenient but that is the price we must pay for speed.