Autor Beitrag
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 29.05.03 13:39 
ja, aber ich möchte gerne, das jeder vierte block eingefärbt wird.
eurer code macht jetzt folgendes:
1 Zeile = Rot
2 Zeile = Grün
3 Zeile = Grün
4 Zeile = Rot
5 Zeile = Grün
6 Zeile = Grün
7 Zeile = Grün
8 Zeile = Rot
ich wollte es gerne so haben.
1 Zeile = Rot
2 Zeile = Rot
3 Zeile = Rot
4 Zeile = Rot
5 Zeile = Grün
6 Zeile = Grün
7 Zeile = Grün
8 Zeile = Grün
und so weiter

_________________
MFG
Michael Springwald, "kann kein englisch...."
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Do 29.05.03 15:46 
Hi,

also ich hab Keine Ahnung was du in deinem Code anstellst, aber das was ich dir gezeigt habe funktioniert! hab es eben nochmal getestet.

Einfach das bei dir in das OnDrawItem vom ListView packen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var
  x: Boolean;

procedure TForm1.ListView1DrawItem(Sender: TCustomListView;
  Item: TListItem; Rect: TRect; State: TOwnerDrawState);
begin
  if item.index mod 4 = 0 then
    x:=not x;
  if x then begin
    ListView1.Canvas.Font.Color:=clYellow;
    ListView1.Canvas.Brush.Color:=clRed;
    ListView1.Canvas.Font.Style:=[fsBold]
  end else begin
    ListView1.Canvas.Font.Color:=clBlue;
    ListView1.Canvas.Brush.Color:=clLime;
    ListView1.Canvas.Font.Style:=[fsBold]
  end;
  ListView1.Canvas.FillRect(Rect);
end;


Wenn es bei dir immernochnet klappt, mach mal nen neues Projekt, pack ne ListView rein und teste es da...

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 29.05.03 17:32 
das ist immer noch nicht was ich will:
if item.index mod 4 = 0 then
toll, ist das ergbnis gerade dann mache das, es ist ungerade das mache dies. aber das will ich doch garnicht.....

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Do 29.05.03 21:46 
Hallo? Hast Du meinen Code überhaupt getestet? Mit dem funzt es 100%ig. Nochmal ganz ausführlich:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
with Sender.Canvas do
begin
  Font.Style := [fsBold];
  if (Item.Index and 4) = 4 then
  begin
    Font.Color := clYellow;
    Brush.Color := clRed;
  end
  else begin
    Font.Color := clBlue;
    Brush.Color := clLime;
  end;
end;
Das in die Routine für OnCustomDrawItem und fertig. Und er macht das genau so, wie Du's oben gepostet hattest. :roll:

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Do 29.05.03 22:18 
Danke, es hat so funktioniert wie ich es haben wollte :D
mal ne frage:
was macht:
ausblenden Delphi-Quelltext
1:
(Item.Index and 4)					

da das and ? und was ist der unterschied zu mod ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Fr 30.05.03 02:08 
Das ist ein bitweises und. Kurz gesagt überprüfst Du mit (x and 4)=4, ob das 3. Bit von x gesetzt ist, und das ändert sich alle 4 Zahlen. Bei 5er-Blöcken wäre das nicht so einfach gegangen.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 30.05.03 13:26 
ich dachte das man es jetzt einfach auch auf andere zahlen übertragen könnte z.b. bei 3 blöcke. so ganz habe ich den and opp noch nicht verstanden :(

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Fr 30.05.03 14:01 
Bei 3er-Blöcken (oder anderen) müsstest Du prüfen, ob Odd(Item.Index div 3). Das kannst Du immer machen. Bei 4er-Blöcken wäre es:
Odd(Item.Index div 4)
Das ist gleichbedeutend mit
Odd(Item.Index shr 2)
Was wiederum gleichbedeutend ist mit
((Item.Index shr 2) and 1) = 1
Was wiederum dasselbe ist wie
(Item.Index and 4) = 4
Deshalb geht's bei 4er-Blöcken einfacher (und schneller). Bei 3er-Blöcken geht das nicht, denn 3 ist keine Zweierpotenz.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Fr 30.05.03 15:06 
mimi hat folgendes geschrieben:
ich dachte das man es jetzt einfach auch auf andere zahlen übertragen könnte z.b. bei 3 blöcke. so ganz habe ich den and opp noch nicht verstanden :(

um nochmal auf das Beispiel von mir zurückzukommen...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
var 
  x: Boolean; 

procedure TForm1.ListView1DrawItem(Sender: TCustomListView; 
  Item: TListItem; Rect: TRect; State: TOwnerDrawState); 
begin 
  if item.index mod 4 = 0 then 
    x:=not x; 
  if x then begin 
    ListView1.Canvas.Font.Color:=clYellow; 
    ListView1.Canvas.Brush.Color:=clRed; 
    ListView1.Canvas.Font.Style:=[fsBold] 
  end else begin 
    ListView1.Canvas.Font.Color:=clBlue; 
    ListView1.Canvas.Brush.Color:=clLime; 
    ListView1.Canvas.Font.Style:=[fsBold] 
  end; 
  ListView1.Canvas.FillRect(Rect); 
end;


Hier kannst du die Zahl beliebig verändern. Also auch z.B. 3

Und bevor du nun wieder nur sagst "Das geht nicht"... starte mal Delphi, mach ein neues Projekt (Ein NEUES!).
Da packste ne ListView drauf und stellst den ViewStyle auf vsReport. Machst eine Spalte (Column) rein, und 10-20 Items.

Jetzt noch OwnerDraw auf True, den Code von mir in das OnDrawItem und starten... tada...

Au'revoir,
Aya

_________________
Aya
I aim for my endless dreams and I know they will come true!
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 30.05.03 16:08 
bei:
ListView1.Canvas.FillRect(Rect);
gibt es eine fehlermeldung, er kann mit Rect nichts anfagen.
und als ich diese zeile auskommetiert hatte, hatte er mir folgedes angezeigt:
1 Zeile = Grün
2 Zeile = Rot
3 Zeile = Rot
4 Zeile = Grün
5 Zeile = Rot
.......

_________________
MFG
Michael Springwald, "kann kein englisch...."
Aya
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1964
Erhaltene Danke: 15

MacOSX 10.6.7
Xcode / C++
BeitragVerfasst: Fr 30.05.03 16:12 
Hi,

welchen Event der ListView hast du benutzt...?

Au'revoir,
Aya~

_________________
Aya
I aim for my endless dreams and I know they will come true!
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 30.05.03 16:30 
den ListView1DrawIte nutze ich

_________________
MFG
Michael Springwald, "kann kein englisch...."
worm
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 135


D6 Prof
BeitragVerfasst: Fr 30.05.03 20:21 
@mimi: Wenn Du OnCustomDrawItem nimmst, dann brauchst weder OwnerDraw setzen noch FillRect benutzen (nur die Farbe des Brushs ändern reicht schon).
@Aya: Sorry, aber deine Lösung ist ganz schnell am Ende, wenn der User anfängt, in der Liste hin und her zu scrollen! Und auch beiif Odd(ItemIndex div n) thenkannst Du jede beliebige Zahl für n einsetzen; ich hab's halt nur etwas optimiert bei den 4er-Blöcken.

_________________
In the beginning, the universe was created. This has made a lot of people very angry, and is generally considered to have been a bad move.
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 30.05.03 21:26 
und wie mache ich es bei blöcke ?
oder bei 6 ?

_________________
MFG
Michael Springwald, "kann kein englisch...."