9.10. Sort a List View by Any Column


You need to sort a list view, but the built-in ListView.Sort method sorts based on only the first column.


Create a type that implements the System.Collections.IComparer interface and can sort ListViewItem objects. The IComparer type can sort based on any ListViewItem criteria you specify. Set the ListView. ListViewItemSorter property with an instance of the IComparer type before calling the ListView.Sort method.

How It Works

The ListView control provides a Sort method that orders items alphabetically based on the text in the first column. If you want to sort based on other column values or order items numerically, you need to create a custom implementation of the IComparer interface that ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.