Say I have a large listbox with rows populated by text dates that look like
myDate.ShortDate + " " + myDate.ShortTime
Can you think of an instance when the default lexicographic sort would fail? In some unusual foreign date format?
Do I need to store the date and implement listbox.comparerows which is somewhat slower?
[quote=127856:@Stephen Dodd]Say I have a large listbox with rows populated by text dates that look like
myDate.ShortDate + " " + myDate.ShortTime
Can you think of an instance when the default lexicographic sort would fail? In some unusual foreign date format?
Do I need to store the date and implement listbox.comparerows which is somewhat slower?[/quote]
Depending on what your short date format is June 1 could sort after July 1
I’d agree with jim - put SOMETHING into the cell tag which cab be sorted correctly & use that (YYYYMMDD is one of my favorites)
ShortDate doesn’t normally use leading zeros, so anything after September will fail. Ie., 10/1/14 will sort before 9/30/14. For that matter, unless you have 4 digit years, anything before 2000 will fail. Use the CompareRows event as everyone has suggested.
You guys are right. It was wishful thinking without actually thinking
I actually store an object in the cell tag (for other uses as well) and on CompareRows I cast it from the variant back to the original object and extract the date.totalseconds that is a property in the object.
How expensive is casting? I’m trying to speed up listbox sorting that seems to have slowed down significantly sometime in the past year of Xojo updates.
Well, I changed to storing the date.totalseconds in the cell tag and comparing that on CompareRows. The result is about a 3x speed improvement.
Now granted in my previous version I was calling another method to get the object in the cell tag in that row and that may affect things too. So the speed improvement comes from some combination of removing casting, removing a method call, removing accessing an object’s property.