home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / Bonus / Plasmatech / ptscp_examples.exe / %MAINDIR% / Examples / CustomColumns / Delphi / FMain.pas < prev   
Encoding:
Pascal/Delphi Source File  |  2001-08-31  |  2.3 KB  |  79 lines

  1. unit FMain; // Copyright ⌐ 1998 Plasmatech Software Design. You can use code from this file in your own projects without credit.
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ComCtrls, UPTTreeList, UPTShellControls, UPTSplitter;
  8.  
  9. type
  10.   TFrmMain = class(TForm)
  11.     PTSplitter1: TPTSplitter;
  12.     PTShellTree1: TPTShellTree;
  13.     PTShellList1: TPTShellList;
  14.     procedure PTShellList1FillComplete(Sender: TObject);
  15.     procedure PTShellList1Insert(Sender: TObject; Item: TListItem);
  16.   private
  17.     FIsFolder: Boolean;
  18.     FCustomColumnId: Integer;
  19.   public
  20.   end;
  21.  
  22. var
  23.   FrmMain: TFrmMain;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29.  
  30. {
  31.  This OnInsert event is called after each list item is added to the control.
  32.  The TPTShListData object for the item can be retrieved with the
  33.  GetDataFromItem method as shown.
  34.  
  35.  The call to PTShellList1.Folder.PathName is relatively CPU expensive for
  36.  such a frequently called routine, so it is only called for the first item
  37.  added to the listview.
  38. }
  39. procedure TFrmMain.PTShellList1Insert(Sender: TObject; Item: TListItem);
  40. begin
  41.   if PTShellList1.Items.Count=1 then
  42.     FIsFolder := PTShellList1.Folder.PathName <> '';
  43.  
  44.   if FIsFolder then
  45.     Item.SubItems[0] := '('+PTShellList1.GetDataFromItem(Item).DisplayName+')';
  46. end;
  47.  
  48.  
  49. {
  50.  This OnFillComplete event is called at the end of fill process for the
  51.  listview control. It is here we add the custom column and remove all but
  52.  the 'Name' system columns.
  53. }
  54. procedure TFrmMain.PTShellList1FillComplete(Sender: TObject);
  55. begin
  56.   if PTShellList1.Folder.PathName <> '' then  // Can't use FIsFolder since OnInsert won't be called if there are no items.
  57.   begin
  58.     PTShellList1.Columns.BeginUpdate;
  59.     try
  60.       with PTShellList1.Columns.Add do  // Add our new column first, otherwise the SubItems we just added will be deleted
  61.       begin
  62.         Caption := 'My Column';
  63.         if PTShellList1.Items.Count > 0 then
  64.           Width := -1  // Autosize to widest item
  65.         else
  66.           Width := 100;
  67.       end;
  68.  
  69.       while PTShellList1.Columns.Count > 2 do  // Delete all other columns, leaving the Name and custom columns.
  70.         PTShellList1.Columns[1].Free;
  71.     finally
  72.       PTShellList1.Columns.EndUpdate;
  73.     end;
  74.   end;
  75. end;
  76.  
  77.  
  78. end.
  79.