Sorting ShellListview by clicking column

Posted by Alan bailey on December 11, 2008

Just to say - I tried the code and it worked first time (after hours of trying do do it in other ways I now have SOME hair left). I 'improved' by adding the following code - in the globals I put ascending:array[1..4] of boolean; and in the FormActivate procedure I set them to false;
In the columnclick procedure I reversed the setting for the column

ascending[sortcolumn]:=not ascending[sortcolumn];
{since the first time you click it it changes from false to true it will sort ascending}
The shellcompare procedure now has this in it.
if ascendingsort[Columntosort] then
Result := Smallint(
TShellFolder(Item1).ParentShellFolder.CompareIDs(
Columntosort,
TShellFolder(Item1).RelativeID,
TShellFolder(Item2).RelativeID) )
else
Result := Smallint(
TShellFolder(Item1).ParentShellFolder.CompareIDs(
Columntosort,
TShellFolder(Item2).RelativeID,
TShellFolder(Item1).RelativeID) );

The above means one click on the column will sort it ascending and second click will reverse the order.

Thank you so much for the code.

Alan Bailey

Related articles