Custom Sort Order

  • Thread starter Thread starter Ethan Strauss
  • Start date Start date
E

Ethan Strauss

Hi,
I want to be able to create a custom sort order for a Sorted List.
Specifically, I have a grid which goes from A1 to H12. The default sort
gives me A10, A11, A1, A2 ... I would like to change it so that it first
sorts by the alphabetical character and then the number. I have figured out
that I need to use IComparer, but I can't figure how to set up IComparer.
Can anyone help?
Thanks!
Ethan
 
Hi,
I want to be able to create a custom sort order for a Sorted List.
Specifically, I have a grid which goes from A1 to H12. The default sort
gives me A10, A11, A1, A2 ... I would like to change it so that it first
sorts by the alphabetical character and then the number. I have figured out
that I need to use IComparer, but I can't figure how to set up IComparer.
Can anyone help?
Thanks!
Ethan
The simplest way may be to change the names of the grid. A01, A02,
A03 etc. will sort correctly.

rossum
 
In pseudo-code:

Split this into alpha and numeric components.
Split "Other" into alpha and numeric components.
int retval = thisAlpha.CompareTo(otherAlpha)
if retval <> 0 return retval
return int.parse(thisNumeric).compareto(int.parse(otherNumeric))

Basically, what you are doing is comparing the alpha parts first and if they
are equal, converting the numeric parts to integers and comparing them.

Mike.
 
Back
Top