Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am trying to sort my grid control column which contains text. I have one issue. When i am sorting everything in ascending order it puts "AA" before "aa", it is putting the Capital letters first and then the small letters, how to reverse this? does everyone see the same problem or has anyone solved. it.

I want the ascending sort result to be of type ::

aa
bb
AA
Ab

etc
Posted

This is due to the order of the characters in the ASCII character set (see here[^]); this is something you should really understand if you are going to do any form of data manipulation in your programs. I am not sure if the grid control has any properties that allow you to modify the sort order, if not you will have to write your own sort subroutine.
 
Share this answer
 
You should typically uses a localized sort when displaying data to the user.

Normally in a sort, capitalization don't matters except when a string only differ in capitalisation.

I would think that in most language capital letter come first.

Thus, the typically sorted output should be:

AA
aa
Ab
bb


C++ has locale for that... but I never used them. I was generally using Windows sort functions

lstrcmp Function (Win32 API)[^]

When the sorting is used for display purpose, sort should typically be done according to text language (or OS language). When sort is only used internally, default sort might be appropriate.
 
Share this answer
 
The expected output definitely calls for a custom sorting routine.
You could use the std::sort function with a user defined predicate function that puts all lower case before upper case.
The ASCII table posted by Richard is a must know.
 
Share this answer
 
I got the solution, i tried to use std::sort etc etc, i don't have much knowledge on it.

So when comparing the string in the end compare function, i am reversing the input text in the end function, i am changing small letters to caps and caps to small letters, this is a workaround for now but its giving me the results i want.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900