Board index » cppbuilder » still sorting.. (dates)

still sorting.. (dates)


2004-11-16 03:28:33 AM
cppbuilder114
Hi!
Does someone know how to sort dates in a listview ? I managed now to sort
alpha, integers, floats but not dates
How do I know if a column holds date values (DD.MM.YYYY HH:MM:SS) ? Is there
some way to test that and then choose which sorting method to use ?
Jani
 
 

Re:still sorting.. (dates)

dear Jani,
look at the attachment.group i posted there a stringgrid sorting
demo for you, good luck...
let me know if something is not readable for you..the program
is in german :-)
Oren
 

Re:still sorting.. (dates)

Oren,
Do you have an English version of your stringgrid sort demo?
Thanks in Advance!!!!
Wayne
"Oren Halvani" < XXXX@XXXXX.COM >wrote in message
Quote
dear Jani,

look at the attachment.group i posted there a stringgrid sorting
demo for you, good luck...

let me know if something is not readable for you..the program
is in german :-)



Oren




 

{smallsort}

Re:still sorting.. (dates)

"Wayne Smith" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
Quote
Oren,
Do you have an English version of your stringgrid sort demo?
Thanks in Advance!!!!
Wayne
sorry Wayne,
i'm developing german software..but the demo isn't hard to understand,
take a deeper look..it's self explaining
Oren
 

Re:still sorting.. (dates)

"Jani Ruohomaa" < XXXX@XXXXX.COM >wrote:
Quote
Hi!

Does someone know how to sort dates in a listview ? I managed
now to sort alpha, integers, floats but not dates. How do I
know if a column holds date values (DD.MM.YYYY HH:MM:SS) ? Is
there some way to test that and then choose which sorting
method to use ?
Here is my code for comparing dates. However, it is a TProfGrid
I am sorting, but the compare routine should be about the same
(never sorted a TListView). Moreover I use BCB 6 Enterprise, so
I don't know if all methods I use are available in your system.
else if(AColDataType == ocdtDateTime)
{
TDateTime dt1, dt2;
if(AString1 == AString2)
Result = 0;
else if(!TryStrToDateTime(AString1, dt1))
Result = SortDescending ? -1 : 1;
else if(!TryStrToDateTime(AString2, dt2))
Result = SortDescending ? 1 : -1;
else
Result = (dt1>dt2) ? 1 : -1;
}
What I do is this: If the strings are equal there is no need to
transform into TDateTime values, just return with Don't-Sort-
Flag. Else I test if it is a TDateTime and transform. If the
TryStrToDateTime isn't available, you will have to use a try-
catch-block. If it is not a date I return the value to place it
at the end of the list (the SortDescending flag tells me if
sort order is asc or desc). If all goes fine, I compare the
dates. As you can see, I have a flag for each column telling me
what kind of data it holds (AColDataType).
Hope this helps a little.
Thorsten.
 

Re:still sorting.. (dates)

Well if you managed to sort floats, then TDateTime should be no problem as
it is stored as a float type. Just use the float of the TDateTime component
and you are all set... either by using a TDateTime attached to each listview
item or by parsing the string values into a TDateTime first, then making the
comparison. If I am not mistaken, TListViewItem has a tag property, no? If
so, just allocate a TDateTime variable to it and use that for your
comparison. Just remember to delete the tag by using the ListViews OnDelete
event or you will have memory leaks.
Lynn
"Jani Ruohomaa" < XXXX@XXXXX.COM >wrote in message
Quote
Hi!

Does someone know how to sort dates in a listview ? I managed now to sort
alpha, integers, floats but not dates
How do I know if a column holds date values (DD.MM.YYYY HH:MM:SS) ? Is
there
some way to test that and then choose which sorting method to use ?

Jani