Autor Beitrag
mexx
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mi 07.12.05 12:07 
Hallo,

ich fülle mein Liestview folgender massen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
       //Listview füllen
        with Inter.ListView1 do
         begin
          ListItem := Items.Add;
          Listitem.Caption := Eintrag;

          ListItem.SubItems.Add(IPs[I]);
          ListItem.SubItems.Add(PCs[I]);
          ListItem.SubItems.Add(Zeits[I]);
          ListItem.SubItems.Add(Datums[I]);
          ListItem.SubItems.Add(Phones[I]);
         end;


Funktioniert alles bestens. Nun möchte ich aber für die bessere Übersichtlichkeit, jede 2. Zeile etwas grauer haben. UND...ich füge nach einer Ping-Prüfung noch einen Eintrag hinzu.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
    IF Ping(IP,1) = true then
     begin
      ListView1.Items.Item[i].SubItems.Append('open');
     end
      else
       begin
        ListView1.Items.Item[i].SubItems.Append('close');
       end;


Nun möchte ich aber auch, dass die Spalte mit einem close rot gefärbt wird.

Das Färben beruht sicherlich auf dem selben Prinzip. Aber wie färbe ich?

Lg Mexx
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mi 07.12.05 12:29 
Eigentlich über das Zeichnen der Zellen im OnItemDraw Ereignis.
Da gibt es aber wirklich schon viele Anfragen, in denen das beschrieben wird ;)
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Mi 07.12.05 13:24 
Zum einen funktioniert folgender Quelltext nicht und zum anderen möchte ich wissen, wie ich nur das Wort open oder close, grün oder rot färben könne.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TInter.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  with ListView1.Canvas.Brush do
  begin
    if Item.SubItems.Text = 'close' then Color := clred;
  end;
end;
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mi 07.12.05 16:40 
Cnavas.Font.Color setzen, Canvas.Textout den text ausgeben.
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 08.12.05 08:38 
Funktioniert, aber zu gut. Er hört nicht auf mit dem Zeichnen. Die Tabelle ist nur am Zabbeln. Da die Subitems zur Laufzeit gefüllt werden, setze ich einen wert auf true, nachdem die Inhalte ausgelesen wurden. Wenn dieser wert true ist, startet auch das CustomDrawSubItem Ereigniss. Jedoch macht der folgende code alles grün. Ohne den wert x auf false zu setzten funktioniert auch alles, nur er hört nicht auf mit dem Zeichnen und zabbelt nur. Ich brauche aber auch eine art stop.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
If x = true then
 begin
  with ListView1.Canvas.Brush do
   begin

    if Item.SubItems.Strings[5] = 'close' then  Font.Color:= clred;
    if Item.SubItems.Strings[5] = 'open' then  Font.Color:= clgreen;
   end;
 end;

x := false;
petergensfeld
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

Windows Vista 32-Bit
Delphi XE Professional
BeitragVerfasst: Do 08.12.05 10:01 
ausblenden Delphi-Quelltext
1:
2:
3:
// [...]
  with ListView1.Canvas.Brush do
// [...]

Lass mal das Brush weg!

Gruß, Dirk
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 08.12.05 10:17 
Dann passiert garnix!
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 08.12.05 10:20 
So gehts.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
If x = true then
 begin
  with ListView1.Canvas do
   begin

    if Item.SubItems.Strings[5] = 'close' then  Font.Color:= clred;
    if Item.SubItems.Strings[5] = 'open' then  Font.Color:= clgreen;
   end;
 end;

//x := false;
petergensfeld
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46

Windows Vista 32-Bit
Delphi XE Professional
BeitragVerfasst: Do 08.12.05 10:31 
Hallo mexx,

die Eigenschaft, die Du ändern möchtest heißt Listview1.Canvas.Font.Color, Listview1.Canvas.Brush ist für den Hintergrund zuständig (Farbe, Muster etc.) - das hat hier nix zu suchen und führt zu dem von Dir beschriebenen "Zappel"-Effekt. Du brauchst auch kein "Stop", die DrawItem-Routine wird vom System automatisch immer dann ausgeführt, wenn etwas neu gezeichnet werden muss (etwa, wenn Du zur Laufzeit (Sub-)Items hinzufügst, Dein Fenster verschoben wird etc.). Wenn Du den Aufruf der Routine erzwingen willst, musst Du ein Listview1.Repaint ausführen.

So sollte es gehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if Item.SubItems.Count > 5 then
begin
  with ListView1.Canvas do
  begin
    if Item.SubItems.Strings[5] = 'close' then  Font.Color:= clred
    else if Item.SubItems.Strings[5] = 'open' then  Font.Color:= clgreen;
  end;
end;


Gruß, Dirk
mexx Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1183



BeitragVerfasst: Do 08.12.05 10:47 
Danke für die Hilfe...besonders ür die Theorie.