Of course, DotNet has its own way of doing it which looks equally troubling.
The easiest workaround is simply to change your date format to be YMD but that isn’t typically a good solution for US companies or applications that show the long date.
But there’s an easier way. It was briefly noted here but I wanted to give VFP developers a very straightfoward example.
Short Answer: Create a new column on the list view with a width of zero. Populate the list with the DTOS or sortable version of the value and then instead of setting the SortKey to the displayed column – set it to the OTHER column instead.
This works like a charm.
Some code (if you will)
In the ColumnClick method of the ListView, put in
IF columnheader.Text = “Date”
THIS.SortKey = columnheader.Index
THIS.SortKey = columnheader.index-1
lo = .ListItems.Add(,”NewFile”,”New File”)
lo.SubItems(1) = DTOC(DATE())
lo.SubItems(2) = DTOS(DATE())
lo = .ListItems.Add(,”OlderFile”,”Old File”)
lo.SubItems(1) = DTOC(GOMONTH(DATE(),-5))
lo.SubItems(2) = DTOS(GOMONTH(DATE(),-5))
lo = .ListItems.Add(,”ROlderFile”,”Really Old File”)
lo.SubItems(1) = DTOC(GOMONTH(DATE(),-12))
lo.SubItems(2) = DTOS(GOMONTH(DATE(),-12))
.View = 3
.Sorted = .T.
Now a few things to note:
1. ListViews can only show TEXT in their columns. That’s why I’m using DTOC which makes it appear in the standard format but then DTOS to put it into a useful SORTABLE format
2. The ColumnClick method shown here is really basic. If you wanted to add support for ascending and descending orders, it might look like this:
IF THIS.sortOrder = 0
THIS.SortOrder = 1 && Descending
THIS.SortOrder = 0 && Ascending
IF columnHeader.Text = “Date”
THIS.SortKey = ColumnHeader.Index
THIS.SortKey = ColumnHeader.Index – 1
Now if you need to do this for a number, instead of using DTOC and DTOS , just pad the numbers with zeroes.