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 / CBuilder / FMain.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-08-31  |  2.6 KB  |  68 lines

  1. // Copyright ⌐ 1998 Plasmatech Software Design. You can use code from this file in your own projects without credit.
  2. //---------------------------------------------------------------------------
  3. #include <vcl\vcl.h>
  4. #pragma hdrstop
  5.  
  6. #include "FMain.h"
  7. #include "PTShConsts.h"
  8. //---------------------------------------------------------------------------
  9. #pragma link "UPTSplitter"
  10. #pragma link "UPTShellControls"
  11. #pragma link "UPTTreeList"
  12. #pragma resource "*.dfm"
  13. TFrmMain *FrmMain;
  14. //---------------------------------------------------------------------------
  15. __fastcall TFrmMain::TFrmMain(TComponent* Owner)
  16.     : TForm(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. /*
  21.  This OnInsert event is called after each list item is added to the control.
  22.  The TPTShListData object for the item can be retrieved with the
  23.  GetDataFromItem method as shown.
  24.  
  25.  The call to PTShellList1->Folder->PathName is relatively CPU expensive for
  26.  such a frequently called routine, so it is only called for the first item
  27.  added to the listview.
  28. */
  29. void __fastcall TFrmMain::PTShellList1Insert(TObject *Sender, TListItem *Item)
  30. {
  31.   if (PTShellList1->Items->Count == 1)
  32.     FIsFolder = ! PTShellList1->Folder->PathName.IsEmpty();
  33.  
  34.   if (FIsFolder)
  35.     Item->SubItems->Strings[0] = "(" + PTShellList1->GetDataFromItem(Item)->DisplayName + ")";
  36. }
  37. //---------------------------------------------------------------------------
  38. /*
  39.  This OnFillComplete event is called at the end of fill process for the
  40.  listview control. It is here we add the custom column and remove all but
  41.  the 'Name' system columns.
  42. */
  43. void __fastcall TFrmMain::PTShellList1FillComplete(TObject *Sender)
  44. {
  45.   if (! PTShellList1->Folder->PathName.IsEmpty()) { // Can't use FIsFolder since OnInsert won't be called if there are no items.
  46.     PTShellList1->Columns->BeginUpdate();
  47.     try {
  48.       TListColumn* lc = PTShellList1->Columns->Add(); // Add our new column first, otherwise the SubItems we just added will be deleted
  49.       lc->Caption = "My Column";
  50.       if (PTShellList1->Items->Count > 0)
  51.         lc->Width = -1;  // Autosize to widest item
  52.       else
  53.         lc->Width = 100;
  54.  
  55.       while (PTShellList1->Columns->Count > 2)   // Delete all other columns, leaving the Name and custom columns.
  56.         delete PTShellList1->Columns->Items[1];
  57.  
  58.       PTShellList1->Columns->EndUpdate();
  59.     }
  60.     catch(...) {
  61.       PTShellList1->Columns->EndUpdate();
  62.       throw;
  63.     }
  64.   }
  65. }
  66. //---------------------------------------------------------------------------
  67.  
  68.