Listview filename sort sequence

J

James Hahn

I have a ListView that displays files selected from various folders using a
user-specified selection rule. I want to sort the files in various ways and
have implemented a sorter class to do it, for instance to sort the file date
as a date and not as text.

But the filenames are not listed in the same sequence as in Explorer, which
is some sort of 'Numeric-modified alpha' sequence. Is there a comparer that
will return the correct sort sequence for a filename, or is there a
definition of the rules used in an Explorer sort so I could write my own
comparer?
 
J

James Hahn

Solved it. There is nothing within .Net to do this and I can't find that MS
has issued a formal definition of their rules, but the old StrCmpLogicalW
function will do the comparison and appears to produce the same sequence as
Explorer.

<System.Runtime.InteropServices.DllImport("shlwapi.dll",
charset:=Runtime.InteropServices.CharSet.Unicode)> _
Public Shared Function StrCmpLogicalW(ByVal strA As String, ByVal strB As
String) As Int32
End Function

and then, within the comparer:

compareResult = StrCmpLogicalW(X, Y.)

The charset attribute is needed: even though it's a W funtion it does not
default to Unicode.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top