AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

ListView OnCustomDrawSubItem

Ein Thema von arest · begonnen am 12. Jan 2011 · letzter Beitrag vom 13. Jan 2011
Antwort Antwort
arest

Registriert seit: 27. Sep 2005
Ort: Frankfurt
62 Beiträge
 
Delphi 6 Personal
 
#1

ListView OnCustomDrawSubItem

  Alt 12. Jan 2011, 20:04
hello again,
ich habe eine listview mit einträgen, in der ich prüfen möchte, ob in der 8. spalte text vorhanden ist, und wenn dem so sein sollte, wird diese rot gefärbt... dazu bin ich beim oncustomdrawsubitem ereignis wie folgt vorgegangen:
Delphi-Quellcode:
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
  var i:integer;
begin
  ListView1.DoubleBuffered:=true;
  with Sender.Canvas do
  begin
    Font.Style:=Font.Style-[fsBold];
    Brush.Color:=clWindow;
    Font.Color:=clBlack;
    for i:=0 to form1.ListView1.Items.Count -1 do
    begin
      if (form1.CheckBox1.Checked=true)
      then begin
             if (ListView1.Items.Item[i].SubItems[7] <> '')
             then begin
                    case SubItem of
                      1: Brush.Color:=RGB(88,188,88);
                      2: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      3: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      4: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      5: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      6: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      7: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      8: Brush.Color:=RGB(200,20,20);
                    end;
                  end
             else begin
                    case SubItem of
                      1: Brush.Color:=RGB(88,188,88);
                      2: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      3: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      4: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      5: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      6: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      7: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                      8: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
                    end;
                  end;
           end;
    end;
  end;
end;
die procedure wird ausgeführt, sobald dem listview ein eintrag hinzugefügt/entnommen wird und ich rufe sie manuell über den statuswechsel von der checkbox auf (onclick)! jetzt würde ich erwarten, dass gemäß meiner schleife die gesamte listview durchgegangen wird und für jeden einzelnen eintrag der 7.subitem, sprich die 8. spalte geprüft wird. jedes mal wenn dieses feld leer sein sollte, wird rot gefärbt, ansonsten eben nicht! mein problem ist aber, dass einfach die gesamte 8. spalte rot gefärbt wird... völlig ohne rücksicht auf den jeweiligen eintrag! woran liegt das?

thx
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#2

AW: ListView OnCustomDrawSubItem

  Alt 12. Jan 2011, 21:28
Du läuft nicht über die Liste, die Routine wird eh für jedes Item/Subitem aufgerufen, Du mußt nur entscheiden wie Du in dem Fall Malen willst
Delphi-Quellcode:
procedure TForm1.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
  if Item.SubItems.Count >= SubItem then
    begin
      if Item.SubItems[SubItem-1]='l1_2'
      then Sender.Canvas.Brush.Color := clRed;
      if Item.SubItems[SubItem-1]='L1_1'
      then Sender.Canvas.Brush.Color := clLime;
    end;
end;
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat
Namenloser

Registriert seit: 7. Jun 2006
Ort: Karlsruhe
3.724 Beiträge
 
FreePascal / Lazarus
 
#3

AW: ListView OnCustomDrawSubItem

  Alt 13. Jan 2011, 06:33
Btw kannst du deinen Code deutlich vereinfachen:
Statt
Delphi-Quellcode:
case SubItem of
  1: Brush.Color:=RGB(88,188,88);
  2: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  3: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  4: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  5: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  6: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  7: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  8: Brush.Color:=RGB(200,20,20);
end;
kannst du schreiben
Delphi-Quellcode:
case SubItem of
  1: Brush.Color:=RGB(88,188,88);
  2..7: if (item.Index mod 2 = 1) then brush.Color:=RGB(222,222,222) else brush.Color:=RGB(255,255,255);
  8: Brush.Color:=RGB(200,20,20);
  { würde ich normal anders einrücken, aber die Forensoftware verbockt es }
end;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz