Re: Sorting Datagrid With Hyphen / Dash

From: Chris Mayers (chris_mayersBLUE_at_SUEDEYahoo.Com)
Date: 03/10/05


Date: Thu, 10 Mar 2005 10:07:38 -0000

Thanks for your answer, I kind of understand what you are saying, but do you
have any code samples that would make it a little clearer?

However, this still does not really explain exactly what is going on with
the sorting at the moment.
ie

30-199
30-299
303-01
303-02
30-399
30-499

Regardless of the ASCII value of the hyphen, this sort order is WRONG, all
the '30-' codes should be together, and all the '303' codes should be
together. This sequence only makes sense if you ignore the hyphen completly,
ie:

30199
30299
30301
30302
30399
30499

Therefore, I draw the conclusion that tha DataGrid treats the hyphen as a
'special' character for the purposes of sorting. I guess this is because if
you were sorting proper words you would want (say) 'co-operative' to be
sorted next to 'cooperative'. But surely this behaviour should be
controllable...?? :-/

ALL I want is a way of getting the DataGrid (or DataView) to sort the data
with a proper ASCII sort, without any 'special casing' being applied to any
of the characters...

Anyone got any suggestions on that??

Cheers,

Chris.

"Samuel Kim" <look341@gmail.com> wrote in message
news:1110325517.500209.265740@o13g2000cwo.googlegroups.com...
> Due to their sequence in the ASCII set, - (hyphen) comes before the
> numbers.
> One way you can get around this behavior is to replace the hyphens with
> underscore(_) character and do comparison.
>
> If you change the hyphens to underscore, then you will need to revert
> the changes once you are done - this you may not like so much.
>
> To overcome this you can implement a class that implements the
> IComparator interface and pass it along to the sort mechanism - the
> IComparator instance can read the strings replace hyphen to underscore
> and then compare. This will not require a change of your original data
> and hence may be a cleaner solution - except for the fact that you need
> to create another class.
>



Relevant Pages

  • Re: Hyphens in Excel Sort
    ... "David McRitchie" wrote: ... How about making a helper column and sort on it. ... >> Does anyone know why Microsoft would ignore hyphens and apostrophes in the ... The help says it was designed to be consistant with Windows. ...
    (microsoft.public.excel.programming)
  • Re: Collating sequence / sort
    ... Apostrophes and hyphens are ignored, with one exception: ... Maybe you can change the hypen to a different character, do the sort and then ... Dave Mills wrote: ...
    (microsoft.public.excel)
  • Re: Hyphens in Excel Sort
    ... I don't really know where Windows provides for sorting other than ... How about making a helper column and sort on it. ... >>> Does anyone know why Microsoft would ignore hyphens and apostrophes in the ...
    (microsoft.public.excel.programming)
  • Re: "-" ignored in sort
    ... Apostrophes and hyphens are ignored, with one exception: ... > as a sort using column B plus column C. ... > vlookup is considering a sorted array in the same way that SORT is. ...
    (microsoft.public.excel.misc)
  • Re: erratic format result
    ... No, I've even removed the input mask for the datble field, and then re-added ... the hyphens to all 9-digit codes, ... Format I showed it should work every time - like I said, ...
    (microsoft.public.access.modulesdaovba)