How do I sort columns of integers in a ListView
c#, .net 2.0, Winform
System.Windows.Forms.ListView
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is how I accomplished being able to sort on multiple columns, and being able to sort each column as a number, or as text.
First use this class:
In your form’s constructor, set the sorter like this:
Then handle the ColumnClick even of your listview control like this:
This is all dependent on the Tag property of each column either being set to “Numeric” or not, so the sorter knows how to sort.
In the above example I cast the values as floats when numeric, you may want to change that to int.