Re: Sorting Delphi's ShellListview by clicking columnPosted by webmaster Guido on November 17, 2004 at 22:41:47: In Reply to: Sorting ShellListview by clicking column posted by creeek on November 17, 2004 at 12:57:41: : ... sort a ShellListView by clicking a column header (date, type, name)? ------------------------------- From Delphi 6 onwards, some so-called "shell controls" are included (TShellListView,...) that you can use to simulate the functionality of Windows Explorer. Usually, these Delphi components are located on the Samples page of the component palette. But alas, there is no documentation from Borland... If you have the Delphi source code, you can look for ShellCtrls.pas and modify it as indicated below. Afterwards, remove the shell controls, recompile and install them again. To change in ShellCtrls.pas: --------------------------- TCustomShellListView = class(TCustomListView, IShellCommandVerb) ... public ... // Add the following line: property FolderList: TList read FFolders; ... end; --------------------------- How to use your modified ShellListView? 1. In the implementation section of Form1, add a global variable SortColumn of type integer. ------------------------ unit Unit1; interface ... type TForm1 = class(TForm) ShellListView1: TShellListView; ... procedure ShellListView1ColumnClick(Sender: TObject; Column: TListColumn); ... private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var SortColumn: Integer; function ShellCompare(Item1, Item2: Pointer): Integer; begin Result := Smallint( TShellFolder(Item1).ParentShellFolder.CompareIDs( SortColumn, TShellFolder(Item1).RelativeID, TShellFolder(Item2).RelativeID) ); end; procedure TForm1.ShellListView1ColumnClick(Sender: TObject; Column: TListColumn); begin SortColumn := Column.Index; ShellListView1.FolderList.Sort(ShellCompare); ShellListView1.Invalidate; end; //...your code //... --------------------- Can you please let us know if it worked, or if you encountered problems with this code? Good luck!
Related Articles and Replies
|