WEBINAR: On-demand webcast
How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >
ListView - Sorting by Number or Date
The ListView control that comes with MSCOMCTL.OCX isn't too bad. It supplies us with most of the things that we need, and makes them incredibly easy to code. As a VC++ developer I can tell you that most of the features that we all take for granted can be a real pig to implement using the MFC and API calls.
One thing that this control is sadly lacking in, however, is the ability to sort by number or date. It would also appear to be something that a lot of people are asking for.
For my second attempt, I decided to take a step back, and try something simpler. I decided to make use of the alphabetical sort that has been implemented with the control. It involves locking the window so that no changes in the data are reflected on-screen, re-formatting the list items so that they may be sorted alphabetically, sorting them, and then restoring the original data before unlocking and refreshing the ListView. I know that this is a pig of a way to do things, but it works!
The good news it that the sort is surprisingly fast. On my machine (a PII 350 with 64Mb RAM running NT4), sorting by number takes about 0.4 milliseconds per listitem (when running in the IDE), and by date takes around 0.35ms.
This certainly isn't THE way to sort ListItems by number or date, but it'll me do until Microsoft supply a custom sort for the ListView control.