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?
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?
"The Internet treats censorship as damage and routes around it." - John Gilmore
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()
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Yeah but can I do it using the built-in sorting system?
"The Internet treats censorship as damage and routes around it." - John Gilmore
could you set " 9" istead of "9" ?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
If list view control doesn't have such options to sort by numbers then I'm going to do something like that yes.
"The Internet treats censorship as damage and routes around it." - John Gilmore
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?
"The Internet treats censorship as damage and routes around it." - John Gilmore
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.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.
Last edited by maxorator; 01-05-2007 at 09:56 AM.
"The Internet treats censorship as damage and routes around it." - John Gilmore