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

Listview filename sort sequence

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

Sep 4 '08 #1
Share this Question
Share on Google+
1 Reply


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

"James Hahn" <jh***@yahoo.comwrote in message
news:ed**************@TK2MSFTNGP06.phx.gbl...
>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?
Oct 5 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.