Autor Beitrag
OliverN_26
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 03:27 
Hi

Ich habe leider noch nie mit einer CheckListBox gearbeitet, aber versuche mich seid geraumen Stunden damit.

Mein Problem:
Ich habe z.B. 10 Einträge. Aktiviere ich nun das Kontrollkästchen von Eintrag 5 möchte ich dass zusätzlich zum Häkchen die Hintergrundfarbe dieser Zeile geändert wird.

Kann doch eigentlich nicht so schwer sein aber ich bekomme es einfach nicht hin.

Bin für jeden Tip dankbar.

Danke
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 09.11.10 04:32 
- Nachträglich durch die Entwickler-Ecke gelöscht -
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 16:29 
Hi.

Also den folgenden Code habe ich aus dem Thread den du mir geschickt hast.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.LB_DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var 
  LB : TListbox;
begin
  if Control is TListbox then begin
    LB := Control as TListbox;
    IF LB.Items[Index]='xyz' then 
      LB.Canvas.Brush.Color := clRed 
    else 
      LB.Canvas.Brush.Color := clWhite;
           
    LB.Canvas.FillRect(Rect);
    LB.Canvas.TextOut(Rect.Left, Rect.Top, LB.Items[Index]);
  end;
end;


Soweit habe ich das vorher bereits hinbekommen.
Mein Problem ist dass ich nich nach einem Text "xyz" suche, sondern der Code bei Mausklick ausgeführt werden soll.
Meine Idee war die CheckListBox neuzuzeichnen sobald ein Häkchen gesetzt oder deaktiviert wird:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
  CheckListBox1.Update;
  //CheckListBox1.Repaint;
  //CheckListBox1.Refresh;
end;


Allerdings funktioniert das alles nicht so wie ich mir das denke.

Noch eine Idee?

Danke
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 09.11.10 16:51 
meinst Du so??

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
  LB : TcheckListbox;
begin
  if Control is TcheckListbox then begin
    LB := Control as TcheckListbox;
    IF LB.checked[Index] then
      LB.Canvas.Brush.Color := clRed
    else
      LB.Canvas.Brush.Color := clWhite;
    LB.Canvas.FillRect(Rect);
    LB.Canvas.TextOut(Rect.Left, Rect.Top, LB.Items[Index]);
  end;
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 17:07 
Hi

Zum Code hab ich eher keine Fragen, da mir klar ist dass ich das mit onDrawItem lösen muss.
Mein Problem ist "WIE LÖSE ICH DEN CODE AUS" ?
Eigentlich müsste die CheckListBox ja bei jedem Click neu gezeichnet werden oder?

Muss da nich irgendwas mit 'onClick' / 'onClickCheck' oder sonstiges gemacht werden ?

Danke
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 09.11.10 17:13 
meinst das??
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);
begin
checklistbox1.Invalidate;
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 17:19 
Genau das ist mein Problem.
Nur leider passiert auch mit diesem Code nichts.
Er springt einfach nicht in die onDrawItem Methode.

Woran kann das liegen?
Habs schon mit 'Refresh' / 'Update' / 'Repaint' versucht aber .. Fehlanzeige :-(
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 09.11.10 17:39 
der style steht auf lbOwnerDrawFixed?

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 17:42 
Ich habs gelöst *freu*

Lösung war CheckListBox1.Style
Style darf nicht auf lbStandard stehen. Habs auf lbOwnerDrawVariable gesetzt und nu läufts :-)

Kurze Frage noch:
Wo ist der Unterschied zwischen 'lbOwnerDrawVariable' und 'lbOwnerDrawFixed' ??

Danke schon mal im voraus.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Di 09.11.10 17:47 
bei lbOwnerDrawVariable kannst Du Sachen mache wie:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.CheckListBox1MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
begin
   if (Index and 1) = 1 then Height := 20 else height := 40;

end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
OliverN_26 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 252

Win7 64-Bit, WinXP SP3
Delphi 7 Enterprise
BeitragVerfasst: Di 09.11.10 17:55 
Danke sehr :-)