Home All Groups Group Topic Archive Search About

Sorting the Table.DefaultView

Author
30 Nov 2006 6:32 PM
Joe
I noticed that strings don't sort correctly when they contain numbers.
For example:
Series: 0
Series: 100
Series: 101
Series: 101
Series: 102
Series: 11
Series: 110
Series: 112
Series: 113
Series: 128
Series: 13
Series: 130

Is there anyway to provide a custom sort? I believe string.Compare() does a
proper comparison.

Thanks,
Joe

Author
30 Nov 2006 7:00 PM
William (Bill) Vaughn
It looks correct to me. If you type a column as string, this is what you're
supposed to get.
In this case I pad the numbers with leading zeroes.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
-----------------------------------------------------------------------------------------------------------------------

Show quote
"Joe" <jbassking@noemail.noemail> wrote in message
news:uTOQy4KFHHA.1356@TK2MSFTNGP06.phx.gbl...
>I noticed that strings don't sort correctly when they contain numbers.
> For example:
> Series: 0
> Series: 100
> Series: 101
> Series: 101
> Series: 102
> Series: 11
> Series: 110
> Series: 112
> Series: 113
> Series: 128
> Series: 13
> Series: 130
>
> Is there anyway to provide a custom sort? I believe string.Compare() does
> a proper comparison.
>
> Thanks,
> Joe
>
Author
30 Nov 2006 10:05 PM
Miha Markic [MVP C#]
I would add another column (in-memory) to source table which would contain
numbers as numbers and would sort on this column.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Joe" <jbassking@noemail.noemail> wrote in message
news:uTOQy4KFHHA.1356@TK2MSFTNGP06.phx.gbl...
>I noticed that strings don't sort correctly when they contain numbers.
> For example:
> Series: 0
> Series: 100
> Series: 101
> Series: 101
> Series: 102
> Series: 11
> Series: 110
> Series: 112
> Series: 113
> Series: 128
> Series: 13
> Series: 130
>
> Is there anyway to provide a custom sort? I believe string.Compare() does
> a proper comparison.
>
> Thanks,
> Joe
>
Author
1 Dec 2006 5:52 AM
Cor Ligthert [MVP]
In addition to Bill,

Completely correct Sort Sequence for a String, you won't get it in another
way than by first converting it to a numeric format.

You probably want
000
100
101

etc, but than you should use it that way.

Cor

Show quote
"Joe" <jbassking@noemail.noemail> schreef in bericht
news:uTOQy4KFHHA.1356@TK2MSFTNGP06.phx.gbl...
>I noticed that strings don't sort correctly when they contain numbers.
> For example:
> Series: 0
> Series: 100
> Series: 101
> Series: 101
> Series: 102
> Series: 11
> Series: 110
> Series: 112
> Series: 113
> Series: 128
> Series: 13
> Series: 130
>
> Is there anyway to provide a custom sort? I believe string.Compare() does
> a proper comparison.
>
> Thanks,
> Joe
>

AddThis Social Bookmark Button