Autor Beitrag
rafi@work
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Do 19.06.03 13:47 
Hi!

Ich hab eine Listview mit verschiedenen Einträgen. Ich habe bei der ListView für jede Zeile das gleiche Icon. Wie kann ich verschiedene Icons bei den Einträgen setzen! Danke für eure Hilfe.

gruss
FriFra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Do 19.06.03 14:21 
Du musst den IconIndex entspr. anpassen und natürlich auch ein Image an dieser Position in Deiner ImageList haben.

_________________
Michael
(principal certified lotus professional - developer)
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Do 19.06.03 15:25 
Danke für den Tipp! mfg
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Fr 20.06.03 12:29 
irgendwie funzt es nicht. wie würde ein code beispel dafür aussehen? also wenn eine caption von einem label "bla" ist dann rotes icon, und wenn die caption "blub" ist das grüne icon beim entsprechenden eintrag.

gruss
makena76
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 41



BeitragVerfasst: Fr 20.06.03 22:11 
Hi,

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
 ListView.Items.Add;
 j:=ListView.Items.Count-1;
 ListView.Items[j].Caption:='Haupttitel';
 ListView.Items[j].SubItems.Clear;
 ListView.Items[j].SubItems.Add('SubTitel1');
 ListView.Items[j].SubItems.Add('SubTitel2');
 ListView.Items[j].SubItems.Add('SubTitel3');


So sollte das gehen, hab ich aus meiner Anwendung rauskopiert. Einen Icon kannst auch noch setzen, da musst aber IMO noch eine ImageList einfügen und dann nur auf die ImageId verweisen.

cu makena
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 21.06.03 08:04 
makena76 hat folgendes geschrieben:
Einen Icon kannst auch noch setzen, da musst aber IMO noch eine ImageList einfügen und dann nur auf die ImageId verweisen.

Und er wollte ja wissen wie DAS geht. :wink: Also kopiere ich auch mal ein Beispiel aus meiner Anwendung raus. Die lädt Icons in einem bestimmten Verzeichnis und zeigt sie mit Namen und Bild in der List-View an:
ausblenden Delphi-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:
lv1.Items.Clear; // List-View
lv1.Items.BeginUpdate;
lvimg.Clear; // Imageliste

if(directoryexists(ExtractFilePath(paramstr(0)) + szSharedIcons)) then
  with lv1 do begin
    res := FindFirst(ExtractFilePath(paramstr(0)) + szSharedIcons +
       '\*.ico',faAnyFile,ds);

    while(res = 0) do begin
      mIcon := TIcon.Create;
      try
        mIcon.LoadFromFile(ExtractFilePath(paramstr(0)) +
          szSharedIcons + '\' + ds.Name);

        li            := Items.Add;
        li.Caption    := ds.Name;
        li.ImageIndex := lvimg.AddIcon(mIcon);
      finally
        mIcon.Free;
      end;

      res := FindNext(ds);
    end;
  FindClose(ds);
end;

lv1.Items.EndUpdate;

Die eigentlich interessante Zeile ist
ausblenden Delphi-Quelltext
1:
        li.ImageIndex := lvimg.AddIcon(mIcon);					

Hier wird für das aktuelle List-View-Item der Bildindex auf das zuletzt in die Imageliste angehangene Symbol gesetzt. Nach gleichem Muster lässt sich vorgehen, wenn du eine Imageliste mit festen Symbolen hast, um den Code von makena76 zu benutzen
ausblenden Delphi-Quelltext
1:
ListView.Items[j].ImageIndex := 3;					

würde für das gerade aktuelle List-View-Item das 4. Symbol aus der Imageliste benutzen. usw. usw.

Gruß.