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

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 20.10.03 08:38 
Hallo! Ich habe schon einige Einträge über dieses Thema hier im Forum gelesen, doch war nie die Frage von einer kompletten Zeile. Weiss jemand wie man eine komplette Zeile in einer ListView mit einer anderen Farbe hinterlegen kann. Ich will also nur den Hintergrund der Zeile mit einer anderen farbe verändern, nicht aber die Strings. Für jede Hilfe bin ich enorm dankbar.

mfg
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mo 20.10.03 08:44 
Hallo,

dazu musst Du das OnCustomDrawItem-Ereignis benutzen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  if (Item=nilthen Exit;
  with Sender.Canvas.Brush do
    if Odd(Item.Index) then Color:=clSilver
      else Color:=clWhite;
end;

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 20.10.03 09:00 
Danke, funktioniert schon ganz gut! Aber wie muss der Code aussehen, wenn ich will, dass alle Einträge die bei der zweiten Spalte den String 'Active' haben alle grün sind und bei allen andere gelb.

mfg
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 20.10.03 09:14 
Hi,

einfach durchlaufen und abfragen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
  i: Integer;
begin
  for i := 0 to ListView1.Items.Count - 1 do
    if Item.Index = i then
      if ListView1.Items[i].SubItems[0] = 'Active' then
        ListView1.Canvas.Brush.Color := clGreen
      else
        ListView1.Canvas.Brush.Color := clYellow;
end;


MFG

- Ernesto -
rafi@work Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 147

Win2000 Prof
D7 Enterprise
BeitragVerfasst: Mo 20.10.03 09:33 
Funzt wunderbar!! Danke!
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mo 20.10.03 09:48 
Hallo,

beim Code-Schnipsel von ErnestoChe ist die Schleife überflüssig. Da wird mit Kanonen auf Spatzen geschossen.

Das Draw-Ereignis wird für jeden sichtbaren Eintrag der Liste aufgerufen. Warum muss dann mit einer Schleife noch einmal die Liste komplett durchlaufen werden?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; 
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); 
begin 
  if (Item=nilthen Exit;
  with Sender.Canvas.Brush do
    if Item.SubItems[0] = 'Active' then Color:=clGreen 
      else Color:=clYellow; 
end;

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 20.10.03 09:56 
Hi,

@Smiegel
Danke, für den Hinweis. Du hast natürlich recht. Ich bin nur von der Logik ausgegangen auf die Schnelle.

MFG

- Ernesto -