473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4685
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken R. | last post by:
Hello all, I am relatively new to python but I am having an issue with custom sort functions.. I am trying to sort a list of lists or tuples with arbitrary ascending or descending sorts. For...
4
by: Mike King | last post by:
Is there a way to sort by element names in XSLT, but not in ascending or descenting order but by elements that I specify? <root> <cat /> <dog /> <rabbit /> </root> the sorted result tree
5
by: Marri Suliez | last post by:
Has anyone found some documentation on how to properly subclass a ListBox control and provide custom sorting (when the list items come from a DataSource)? The only way I can figure out how to do...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
5
by: TM | last post by:
I am using an access database in my vb.net application and it is tied to a datagrid. My problem is that the field I want to sort on is a text field, 5 characters long, and it contains not only...
0
by: Wiktor Zychla [C# MVP] | last post by:
Hello, just two sad thoughts on GridView's custom paging support, the first one rather general and second one rather specific. First one: I really miss the DataGrid custom paging support with...
2
by: Emma Burrows | last post by:
I have created a typed dataset in .Net 2.0 based on an Access database, and set up various methods to retrieve specific data from the tables, etc (great fun). However, I need to implement a custom...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Max Odendahl | last post by:
Hi, my own declared class has a stl::list as a member variable. I now need access to those from the outside. Is a custom iterator for my class the best solution for this and how to do this? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.