Sorting Records
The way in which a ListView’s rows are sorted depends on its ListViewItemSorter property. This property gets or sets a reference to an object that implements the IComparer interface. That interface defines a Compare method that the ListView uses when it needs to sort its items.
The ListViewSorter class, shown in Listing 12.5, implements this interface. Its SortColumn property tells the object which ListView column the user clicked. If the user clicked the first column, the Compare method calls the CompareItems method, passing it the text displayed by the two ListView items.
Each row in the ListView represents an item followed by subitems. If the user clicked a column other than the first, the program must sort the data using ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access