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 ...

Get Visual Basic® .NET Database Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.