470,647 Members | 1,056 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

Custom Sort Order

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
Jan 15 '07 #1
5 4556
6/19/2006
Advanced IComparer // Sorting on Multiple Values

http://sholliday.spaces.live.com/blog/
"Ethan Strauss" <ethan dot strauss at Promega dot comwrote in message
news:O1**************@TK2MSFTNGP03.phx.gbl...
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


Jan 15 '07 #2
On Mon, 15 Jan 2007 10:05:27 -0600, "Ethan Strauss" <ethan dot strauss
at Promega dot comwrote:
>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

Jan 15 '07 #3
Hi,

"sloan" <sl***@ipass.netwrote in message
news:uV*************@TK2MSFTNGP06.phx.gbl...
| 6/19/2006
| Advanced IComparer // Sorting on Multiple Values
|
| http://sholliday.spaces.live.com/blog/

Weird, when I try to open the page my IE 6 crash, which browser r u using?
Jan 15 '07 #4
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(otherNu meric))

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.


"Ethan Strauss" <ethan dot strauss at Promega dot comwrote in message
news:O1**************@TK2MSFTNGP03.phx.gbl...
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



Jan 16 '07 #5
On Mon, 15 Jan 2007 19:46:24 +0100, Ignacio Machin ( .NET/ C# MVP )
<machin TA <"laceupsolutions.com>"wrote:
Hi,

"sloan" <sl***@ipass.netwrote in message
news:uV*************@TK2MSFTNGP06.phx.gbl...
| 6/19/2006
| Advanced IComparer // Sorting on Multiple Values
|
| http://sholliday.spaces.live.com/blog/

Weird, when I try to open the page my IE 6 crash, which browser r u
using?

Works fine in IE 7, Opera 9 and Firefox 2. At least today.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 16 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ken R. | last post: by
4 posts views Thread by Mike King | last post: by
5 posts views Thread by Marri Suliez | last post: by
reply views Thread by Wiktor Zychla [C# MVP] | last post: by
2 posts views Thread by Emma Burrows | last post: by
4 posts views Thread by Ambica Jain | last post: by
7 posts views Thread by Max Odendahl | last post: by
1 post views Thread by Korara | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.