﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Sorting dates in ListView</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sat, 25 Apr 2026 12:45:31 GMT</lastBuildDate><ttl>20</ttl><item><title>Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost20313.aspx</link><description>Hi&lt;P&gt;I have a ListView that works fine, except in one thing.&lt;/P&gt;&lt;P&gt;If I click on any column header the data sorts fine, in numbers and text, but some columns has dates and here the data sort as "numbers", for example, if I have records these:&lt;/P&gt;&lt;P&gt;Date&lt;BR&gt;24/09/2008&lt;BR&gt;15/10/2008&lt;BR&gt;02/10/2008&lt;BR&gt;13/10/2008&lt;BR&gt;10/10/2008&lt;BR&gt;15/09/2008&lt;/P&gt;&lt;P&gt;After clic the column header I got this:&lt;/P&gt;&lt;P&gt;Date&lt;BR&gt;02/10/2008&lt;BR&gt;03/10/2008&lt;BR&gt;10/10/2008&lt;BR&gt;15/10/2008&lt;BR&gt;15/09/2008&lt;BR&gt;24/10/2008&lt;/P&gt;&lt;P&gt;My system date format is (Day/Month/Year), that's why the dates are in that format.&lt;/P&gt;&lt;P&gt;If I click again the order is 24, 15,15,10,03,02&lt;/P&gt;&lt;P&gt;In the Rowpopulating event I have this:&lt;/P&gt;&lt;P&gt;[code]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;e.Values(6).DisplayValue = bo.FechaEnvio.ToShortDateString&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/code]&lt;/P&gt;&lt;P&gt;The sorting is only counting the first digits (the day in my case), Is there a way to fix this, to sort correctly for the complete date?&lt;/P&gt;&lt;P&gt;Kindest regards</description><pubDate>Tue, 24 Feb 2009 15:24:30 GMT</pubDate><dc:creator>Juan Carlos Pazos</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22078.aspx</link><description>OK, I just took a look at the source and I need to be more specific.  I know that I can use my own sorter with the listview and have done that (thanks to some previous help!). However, I was thinking that it'd be nice if I could provide my own sorter and get the nice auto sorting on column clicks etc. In order to get that currently, I need to provide not only the sorter, but also the code to handle column clicks, swap order on columns etc. (not a huge deal...but always looking to leverage the framework).  &lt;br&gt;
&lt;br&gt;
I see that this would actually a bit more work by you, as you not only have to expose the sorter, but also either use a base class or interface, so this would work.  I still think this would be nice, but as you get your sorter worked out, there might be less of a need for what I'm asking.</description><pubDate>Tue, 24 Feb 2009 15:24:30 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22073.aspx</link><description>Actually,&amp;nbsp;it already is.&amp;nbsp; The ListView has a Sorter property that allows you to attach any sorter that you would like.&amp;nbsp; We just happen to attach the ListViewColumnSorter class by default.&amp;nbsp; But you can create your own as this is a function of the ListView control.</description><pubDate>Tue, 24 Feb 2009 12:40:12 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22072.aspx</link><description>I might make the suggestion that you expose the ListViewSorter. That way, if there is some issue with the default provided (or some weird sorting needed), an alternative can easily be provided.</description><pubDate>Tue, 24 Feb 2009 12:06:04 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22069.aspx</link><description>Trent&lt;/P&gt;&lt;P&gt;Thanks for your support and the time invested. I will wait for the next update. &lt;/P&gt;&lt;P&gt;Kindest regards</description><pubDate>Tue, 24 Feb 2009 10:18:27 GMT</pubDate><dc:creator>Juan Carlos Pazos</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22068.aspx</link><description>OK...I found the problem.&amp;nbsp; It will require a change.&amp;nbsp; The column sorter evaluates the column type once and then attempts to sort using that type for all other columns.&amp;nbsp; So if the date is your default column, it will sort dates correctly and not the string and vice versa.&amp;nbsp; I will fix this now and it will be in the next beta posted.&lt;/P&gt;&lt;P&gt;Thanks for the sample!</description><pubDate>Tue, 24 Feb 2009 07:43:26 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22067.aspx</link><description>Juan,&lt;/P&gt;&lt;P&gt;Try this as it worked for me and did not require any change to the framework.&amp;nbsp; I set the column initial column sort index to the date column and it sorted as it should first thing:&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/4cb21213-378c-4038-86a0-5ffa.png"&gt;&lt;/P&gt;&lt;P&gt;So set the DefaultSortColumn = 2 and it should work correctly.</description><pubDate>Tue, 24 Feb 2009 07:39:20 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22064.aspx</link><description>Hi Trent&lt;P&gt;I attach a sample proyect with database, you will see that some records for the second month (february) are miexed with the ones for january.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/3a0d9fc3-effa-444d-aa3e-8e25.gif"&gt;&lt;/P&gt;&lt;P&gt;[quote]&lt;/P&gt;&lt;P&gt;Also, be sure to give me the regional settings that you are using as well so that I can setup this as well.&amp;nbsp; Thanks. &lt;/P&gt;&lt;P&gt;[/quote]&lt;/P&gt;&lt;P&gt;Spanish/Mexico, for dates de Windows format is dd/MM/yyyy&lt;/P&gt;&lt;P&gt;Also I use this for spanish:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;MicroFour.StrataFrame.UI.Localization.MessageLocaleID = 2058&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;Regards</description><pubDate>Mon, 23 Feb 2009 21:05:04 GMT</pubDate><dc:creator>Juan Carlos Pazos</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22055.aspx</link><description>I looked at the ListViewColumnSorter and the dates should be getting sorted properly.&amp;nbsp; In the MicroFour StrataFrame Base assembly under the Windows folder, you will find the ListViewColumnSorter class.&amp;nbsp; It has the logic to determine if the column being sorted is a date.&amp;nbsp; If so, then it will use the CompareDates method and use the DateTime.Parse(...) method to convert the text into a datetime.&lt;/P&gt;&lt;P&gt;However, looking over the code, I see one thing that could be causing your date values to be sorted as a string instead of a date.&amp;nbsp; It has to do with the globalization delimitter.&amp;nbsp; However, to prove this, it would be helpful if you could step through this code or at the very least, give me a sample that reproduces your problem and we will just change the ListViewColumnSorter to make sure it is working in your language.&amp;nbsp; If you are having this issue then it is feasible that someone else may run into this also.&lt;/P&gt;&lt;P&gt;Also, be sure to give me the regional settings that you are using as well so that I can setup this as well.&amp;nbsp; Thanks.</description><pubDate>Mon, 23 Feb 2009 07:52:23 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost22049.aspx</link><description>Hi Trent&lt;P&gt;The time that I need to implement the date sorting, in your last message you taold me the the ListViewColumnSorter class implements the sort for the LV.&lt;/P&gt;&lt;P&gt;I finally arrives there, and I believe that the routine to modifiy is this:&lt;/P&gt;&lt;P&gt;[code]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' Compares two date values.&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;param name="x"&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;The first value to compare.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/param&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;param name="y"&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;The second value to compare.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/param&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;returns&amp;gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;An integer value indicating which value should be placed first.&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/returns&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; CompareDates(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; x &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; y &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;'-- Compare the two rows being tested&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Select&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Case&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; _SortOrder&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Case&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SortOrder.Ascending&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime.Compare(x, y)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Case&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SortOrder.Descending&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime.Compare(y, x)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Case&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SortOrder.None&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; 0&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Select&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;[/code]&lt;/P&gt;&lt;P&gt;But, I don't have any idea of what should I do with this, can you give me an idea of how or what should I do?&lt;/P&gt;&lt;P&gt;My date format is DD/MM/YYYY, in english is MM/DD/YYYY&lt;/P&gt;&lt;P&gt;I believe that I should format the date to the format I use, maybe something like this:&lt;/P&gt;&lt;P&gt;[code]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Return&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; DateTime.Compare(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;CDate&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(Format(x, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"d"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)), &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;CDate&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;(Format(y, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"d"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)))&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/code]&lt;/P&gt;&lt;P&gt;Hope you can point me in the right direction&lt;/P&gt;&lt;P&gt;Regards</description><pubDate>Fri, 20 Feb 2009 20:04:34 GMT</pubDate><dc:creator>Juan Carlos Pazos</dc:creator></item><item><title>RE: Sorting dates in ListView</title><link>http://forum.strataframe.net/FindPost20319.aspx</link><description>The quickest way around this may be for you to create your own ListColumnSorter class.&amp;nbsp; You can copy of the SF column sorter and create your own.&amp;nbsp; It just uses an IComparable interface to sort the records.&amp;nbsp; This will give you control to sort the dates however you would like.&amp;nbsp; This is something that we can add to the list, but since it is character at this point, it will mean that we will have to sort differently for every region which will require a bit of energy (meaning time for implementation and testing at a global level for the framework).&amp;nbsp; You can move much faster on your own to get your needs met immediately.&amp;nbsp; But I will add this to the list to look at since I am pretty confident that a U.S. format is all that is being respected at the moment.</description><pubDate>Fri, 24 Oct 2008 08:07:14 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>