Autor Beitrag
N1m3
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30


Borland Delphi 2005 Personal
BeitragVerfasst: Fr 15.07.05 17:32 
Hi zusammen

Ich möchte gerne eine CheckListBox mit einem headerControl funktionieren lassen, ich hab dann euer Tut(www.delphi-forum.de/viewtopic.php?t=22048) dazu ausprobiert hat natürlich super geklappt 8) .

Nur bei diesem Tutorial hab ich auch eine ListBox zur Hand genommen mit welchem es auch funktionierte.

Jetzt möchte ich das ganze mit einer CheckListBox ausführen, was aber nicht Fehlerlos erfolgt :( .

Den ersten fehler hab ich heir erhalten :   with (Control as TListBox)  do begin was ich einfach mal zu   with (Control as T[b]Check[/b]ListBox)  do begin änderte.

Danach ist aber noch ein zweiter Fehler aufgetreten:

In dieser Zeile:
ausblenden Delphi-Quelltext
1:
    if odSelected in State then Canvas.Font.Color := clCaptionText					


sollte anstelle von 'then' ein '[' stehen :?: warum klappt das mit einer check list box nicht.


Grüsse N1m3
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Fr 15.07.05 18:08 
Ich geh mal davon aus, dass sich die fehlerhafte Stelle im OnDrawItem befindet. Dort geht bei mir jedoch alles wunderbar. Poste doch bitte mal die gesamte Methode, damit wir dir helfen können.

Gruß,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
N1m3 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30


Borland Delphi 2005 Personal
BeitragVerfasst: Fr 15.07.05 19:24 
Zur Oberfläche gibts noch zu sagen das 'CheckListBox' bei Style auf 'lbOwnerDrawFixed' was man im Script ja nicht erkennen kann. Beim CheckListBox Event OnDrawItem steht: CheckListBox1DrawItem , den Code hab ich auch dazukopiert.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
procedure DrawListBoxHContr(Control: TWinControl; Index: Integer; Rect: TRect;
  State: TOwnerDrawState; HeaderControl1: THeaderControl);

  function Rec(R: TRect; L, W: Word): TRect;
  begin
    with R do Result := Classes.Rect(Left + L, Top, Left + L + W, Bottom);
  end;
var
  k, l1, l2: Integer;
  sl: TStringList;
const
  Col: array [Boolean] of TColor = (clInactiveCaptionText, clWindowText);
begin
  with (Control as TCheckListBox)  do begin
    if odSelected in State then Canvas.Font.Color := clCaptionText
      else Canvas.Font.Color := Col[(Control as TListBox).Enabled];

    sl := TStringList.Create;
    try
      sl.CommaText := Items[Index];

      while sl.Count < HeaderControl1.Sections.Count do sl.Add('');

      l1 := 0;
      for k := 0 to HeaderControl1.Sections.Count - 1 do begin
        l2 := HeaderControl1.Sections[k].Width;
        Canvas.TextRect(Rec(Rect, l1, l2), Rect.Left + l1, Rect.Top, sl[k]);
        l1 := l1 + HeaderControl1.Sections[k].Width;
      end;

      { den Rest mit leerer Fläche zeichen, sonnst Canvas-Darstellungsfehler }
      l2 := HeaderControl1.Width - l1;
      Canvas.TextRect(Rec(Rect, l1, l2), Rect.Left + l1, Rect.Top, '');
    finally
      sl.Free;
    end;
  end;
end; {Popov}

procedure TForm1.HeaderControl1SectionResize(HeaderControl: THeaderControl;
  Section: THeaderSection);
begin
  CheckListBox1.Repaint;
end;

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  DrawListBoxHContr(Control, Index, Rect, State, HeaderControl1);
end;



Vielen Dank im Vorraus, N1m3
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Fr 15.07.05 21:26 
Ganz einfaches Problem: Die TCheckListBox hat eine Eigenschaft, die State heißt, d.h. dass Delphi den State der Komponente benutzt (da ein with davor steht) und nicht die Variable. Folgende einfache Lösung: In Zeile 2 und 15 statt State einfach xState (o.ä.) schreiben.

Gruß,
maxk


PS: :welcome: im DF!

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
N1m3 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 30


Borland Delphi 2005 Personal
BeitragVerfasst: Fr 15.07.05 21:40 
Hi maxk
jetzt funktioniert es, ich musste wirklich nur ein x vor State setzen.

Danke