Board index » cppbuilder » still sorting.. (dates)
Jani Ruohomaa
CBuilder Developer |
Jani Ruohomaa
CBuilder Developer |
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 |
Oren Halvani
CBuilder Developer |
2004-11-16 07:09:27 AM
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 |
Wayne Smith
CBuilder Developer |
2004-11-19 04:17:28 AM
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 Quotedear Jani, {smallsort} |
Oren Halvani
CBuilder Developer |
2004-11-19 07:15:30 AM
Re:still sorting.. (dates)
"Wayne Smith" < XXXX@XXXXX.COM >schrieb im Newsbeitrag
QuoteOren, take a deeper look..it's self explaining Oren |
Thorsten Kettner
CBuilder Developer |
2004-11-19 11:12:11 PM
Re:still sorting.. (dates)
"Jani Ruohomaa" < XXXX@XXXXX.COM >wrote:
QuoteHi! (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. |
Lynn Morrison
CBuilder Developer |
2004-11-22 10:19:05 AM
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 QuoteHi! |