home *** CD-ROM | disk | FTP | other *** search
- unit FMain; // Copyright ⌐ 1998 Plasmatech Software Design. You can use code from this file in your own projects without credit.
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ComCtrls, UPTTreeList, UPTShellControls, UPTSplitter;
-
- type
- TFrmMain = class(TForm)
- PTSplitter1: TPTSplitter;
- PTShellTree1: TPTShellTree;
- PTShellList1: TPTShellList;
- procedure PTShellList1FillComplete(Sender: TObject);
- procedure PTShellList1Insert(Sender: TObject; Item: TListItem);
- private
- FIsFolder: Boolean;
- FCustomColumnId: Integer;
- public
- end;
-
- var
- FrmMain: TFrmMain;
-
- implementation
-
- {$R *.DFM}
-
-
- {
- This OnInsert event is called after each list item is added to the control.
- The TPTShListData object for the item can be retrieved with the
- GetDataFromItem method as shown.
-
- The call to PTShellList1.Folder.PathName is relatively CPU expensive for
- such a frequently called routine, so it is only called for the first item
- added to the listview.
- }
- procedure TFrmMain.PTShellList1Insert(Sender: TObject; Item: TListItem);
- begin
- if PTShellList1.Items.Count=1 then
- FIsFolder := PTShellList1.Folder.PathName <> '';
-
- if FIsFolder then
- Item.SubItems[0] := '('+PTShellList1.GetDataFromItem(Item).DisplayName+')';
- end;
-
-
- {
- This OnFillComplete event is called at the end of fill process for the
- listview control. It is here we add the custom column and remove all but
- the 'Name' system columns.
- }
- procedure TFrmMain.PTShellList1FillComplete(Sender: TObject);
- begin
- if PTShellList1.Folder.PathName <> '' then // Can't use FIsFolder since OnInsert won't be called if there are no items.
- begin
- PTShellList1.Columns.BeginUpdate;
- try
- with PTShellList1.Columns.Add do // Add our new column first, otherwise the SubItems we just added will be deleted
- begin
- Caption := 'My Column';
- if PTShellList1.Items.Count > 0 then
- Width := -1 // Autosize to widest item
- else
- Width := 100;
- end;
-
- while PTShellList1.Columns.Count > 2 do // Delete all other columns, leaving the Name and custom columns.
- PTShellList1.Columns[1].Free;
- finally
- PTShellList1.Columns.EndUpdate;
- end;
- end;
- end;
-
-
- end.
-