By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,859 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

Custom Sort Order

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.