473,804 Members | 3,353 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Listview filename sort sequence

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
1 2122
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 .InteropService s.DllImport("sh lwapi.dll",
charset:=Runtim e.InteropServic es.CharSet.Unic ode)_
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.co mwrote in message
news:ed******** ******@TK2MSFTN GP06.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1364
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... "Specified argument was out of the range of valid values. Parameter Name: '9' is not a valid value for 'index'." ....when I attempt to "Refresh" a ListView control AFTER it has been sorted.
3
9320
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data, checkbox's and icons are displayed as they are meant to be. My problem is this, I am trying to achieve the same results as I get with CheckListBox(s), where I am able to select (Check-mark) various checkboxs items and able to alter the data. I do...
0
943
by: VP | last post by:
hi, I have written a small app using c# which mimicks a windows folder. However I do not know how to change the background color of a column in a listview that a user clicks upon. I did manage to get a partial solution after viewing some sample code online. Now at the moment my solution doesnot color the entire column that the user clicks upon. The color is rather limited to the number of subitems accumulated. i.e., if the current...
0
1445
by: Mike Barrett | last post by:
I have a strange one here and I believe it is a bug. I googled it and saw others having a similar issue and nobody seems to have a fix. I will take another shot. I get this ERROR MESSAGE... "Specified argument was out of the range of valid values. Parameter Name: '9' is not a valid value for 'index'." ....when I attempt to "Refresh" a ListView control AFTER it has been sorted.
4
5577
by: Ken Swanson | last post by:
Hi, In VB.NET, how do I determine what filename has been dropped into a ListView? In my ListView's DragEnter() event, I am trying this, which according to the Help, should work: MyFilename = e.Data.GetData("FileName").ToString I have also tried e.Data.GetData(DataFormats.Text) and GetData(System.String)... neither work. I keep getting "System.String" back as the filename.
3
2240
by: J M | last post by:
When you set the Listview's property AllowColumnReorder to True, users can reorder the columns (quite logical I guess)... Bus how on earth can I obtain from code what order these columns are in??? I want to save these settings (to the registry or to a file) so that the program can recall which order of columns the user prefers.... Thanks
7
15009
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
0
1784
by: Terry Brown | last post by:
I have a form which contains a listview item. The form is created to view data that is generated by interaction with a separate form. There are buttons on the form that change the data source that is displayed in the listview. The listview can be sorted by clicking on columns in the listview. When I change the data for the listview I use listview1.Clear() to clear the listview, then rebuild the listview by adding the proper columns...
11
10001
by: Alan T | last post by:
Does the ListView supports sort? I want to have a up/down arrow/triangle that show it is sorted asc or desc on the column headers when I click the column header. May be I need a third-party components ?
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10594
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.