views:

1068

answers:

3

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?

+1  A: 

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

BlackWasp
A: 

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.

itsmatt
+1  A: 

ObjectListView (an open source wrapper around .NET WinForms ListView) does exactly this for you automatically.

Grammarian