简体   繁体   中英

How to implement sorting in a listview while maintaining neighboring columns?

I have a ListView that has several columns.

One of them contains "Names", the other contains "Amount". I would like to allow the user to click the Names column in the listview and have it sort alphabetically and also allow the user to click the "Amount" and have it sort numerically (higher/lower - lower/higher).

What is the best way to implement this?

It is partially implemented but not completely. Microsoft have a description of how to approach this problem at http://support.microsoft.com/kb/319401 .

ObjectListView (.NET WinForms ListView的开源包装器)会自动为您完成此操作。

To solve this, I wrote my own ListViewItemComparer which implemented the IComparer interface. Then, based on whether the column was numeric or string, I did the appropriate comparison.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM