I have a column which consists of numbers. I want them to be sorted as numbers (I don't want to add 0s in front of them because they can be quite large numbers), not as text. Can I do it without making my own complex sorting system?
Printable View
I have a column which consists of numbers. I want them to be sorted as numbers (I don't want to add 0s in front of them because they can be quite large numbers), not as text. Can I do it without making my own complex sorting system?
To get "9" before "10", first compare the lengths of the strings to decide on the order.
If the two lengths are the same, then use strcmp()
Yeah but can I do it using the built-in sorting system?
could you set " 9" istead of "9" ?
If list view control doesn't have such options to sort by numbers then I'm going to do something like that yes.
Use the ListView_SortItems Macro to do all your sorting. This will eliminate the need to do any type of numeric padding.
Perfect! Now is there a way to let it sort some of them automatically by the text?
Not sure what you mean by "them". Are you referring to several columns in a listview, some columns are of a "numeric" type and some are of a string type. If this is the case, then your compareProc can be easily modified to sort both types, "numeric" and string. I guess I'm confused by the above statement, please clarify.Quote:
Now is there a way to let it sort some of them automatically by the text?
You got it right. I just thought maybe there are preconstructed sorting ways too... so I wouldn't need to make my own case insensitive string comparing function.