Autor Beitrag
raven
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 54



BeitragVerfasst: Fr 14.02.03 16:42 
hi leutz ;)

Ich liste in einer listview mehrere dateien von verschiedenen datentypen auf ... es gibt mehrere spalten in denen jeweils die infos zur datei stehen (datum, größe, pfad usw.)

Wie ist es möglich das in der ersten spalte wo der dateiname steht auch das passende icon zum jewieligen dateityp angezeigt wird?

Also das es dann so ist wie bei einem windows ordner ...

danke ;)
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Fr 14.02.03 20:34 
verwendest du ein shelllistview oder ein normales listview. bei einen shelllistview werden solche Symbole automatisch angezeigt!
torstenheinze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 461



BeitragVerfasst: Fr 14.02.03 20:41 
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
{ 
  The following example shows how to show all files and their 
  associated icons of a folder in a TListView. 
  To test the code, you need a ListView1 and a ImageList1 where the icons are stored. 

  Im folgenden Beispiel werden alle Dateien & zugehörigen 
  Icons eines Verzeichnisses in einer TListView angezeigt. 
  Um das Beispiel zu testen, braucht man eine ListView1 und eine ImageList1 
  Komponente, wo die Icons gespeichert werden. 
} 


uses 
  ShellApi; 

procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList); 
var 
  i: Integer; 
  Icon: TIcon; 
  SearchRec: TSearchRec; 
  ListItem: TListItem; 
  FileInfo: SHFILEINFO; 
begin 
  // Create a temporary TIcon 
  Icon := TIcon.Create; 
  ListView.Items.BeginUpdate; 
  try 
    // search for the first file 
    i := FindFirst(strPath + '*.*', faAnyFile, SearchRec); 
    while i = 0 do 
    begin 
      with ListView do 
      begin 
        // On directories and volumes 
        if ((SearchRec.Attr and FaDirectory <> FaDirectory) and 
          (SearchRec.Attr and FaVolumeId <> FaVolumeID)) then 
        begin 
          ListItem := ListView.Items.Add; 
          //Get The DisplayName 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo, 
            SizeOf(FileInfo), SHGFI_DISPLAYNAME); 
          Listitem.Caption := FileInfo.szDisplayName; 
          // Get The TypeName 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo, 
            SizeOf(FileInfo), SHGFI_TYPENAME); 
          ListItem.SubItems.Add(FileInfo.szTypeName); 
          //Get The Icon That Represents The File 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo, 
            SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON); 
          icon.Handle := FileInfo.hIcon; 
          ListItem.ImageIndex := ImageList.AddIcon(Icon); 
          // Destroy the Icon 
          DestroyIcon(FileInfo.hIcon); 
        end; 
      end; 
      i := FindNext(SearchRec); 
    end; 
  finally 
    Icon.Free; 
    ListView.Items.EndUpdate; 
  end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  // Assign a Imagelist to the ListView 
  ListView1.SmallImages := ImageList1; 
  // Show Listview in Report Style and add 2 Columns 
  ListView1.ViewStyle := vsReport; 
  ListView1.Columns.Add; 
  ListView1.Columns.Add; 
  LV_InsertFiles('C:\Windows\', ListView1, ImageList1); 
end;