Autor Beitrag
dragonlord
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 10:19 
Hallo zusammen,

ich möchte ein DBGrid einfärben. Aber nicht die komplette Zeile sondern nur
ein bestimmtes Feld jeder Zeile. Weiss jemand wie das geht?
Oder kennt jemand einen Weg wie man das realisieren kann.

Gruss
Dragonlord
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.04.05 10:53 
Schau mal auf meiner HP im Download nach. Da gibts eine Komponente, mit der du sowas realisieren kannst. Wenn du dem Anwender das ermöglichen willst, kannst du die Steuerungsfunktion im Programm zugänglich machen. Du kannst auch Felder ausrichten, ausblenden, formatieren (z.B.: Zahlen).
Guckst du Feld-Formatierer
Wenn du nur sehen willst, wie es geht, kannst du den Source ja ansehen.
dragonlord Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 12:04 
Werd mir das mal ansehen. Leider geht das Momentan noch nicht, da ich z.b. nur die TRIAL von Delphi 2005 habe. Da kann man keine Komponenten einbinden.

Vorab wäre es mir lieb wenn mir jemand einen Typ gibt wie ich sowas auch ohne externe Komponennte realisieren kann.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.04.05 12:08 
Schau mal hier
dragonlord Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 12:23 
Leider werde ich aus diesem Code nicht wirklich schlau. Ich brächte ein konkretes Beispiel. Der Code der in dem Beispiel zugrunde liegt geht ja ein ganz anderes Problem an.

Gruss
Dragonlord
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.04.05 12:34 
Ausschnitt aus meiner Komponente:
ausblenden 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:
procedure TBBDBGridColorControl.DrawGridColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn;State: TGridDrawState);
begin
            if DBGrid1.Focused then begin
              if gdSelected in state then begin
                DBGrid1.Canvas.Font.Color := clBlue;
              end
              else begin
                DBGrid1.Canvas.Brush.Color := clBlue;
              end;
            end
            else begin
              if dgAlwaysShowSelection in DBGrid1.Options then begin
                if gdSelected in state then begin
                  DBGrid1.Canvas.Font.Color := clBlue;
                end
                else begin
                  DBGrid1.Canvas.Brush.Color := clBlue;
                end;
              end
              else begin
                DBGrid1.Canvas.Brush.Color := clBlue;
              end;
            end;
end;

Alles ein bisschen angepasst. Ich hoffe, dass ich nichts übersehen haben. clBlue ist natürlich nur eine Beispiel. Kannst auch andere Farben nehmen.
dragonlord Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 12:42 
Hab es bei mir so eingefügt:

ausblenden 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:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin

if DBGrid1.Focused then begin  
              if gdSelected in state then begin  
                DBGrid1.Canvas.Font.Color := clBlue;
              end  
              else begin  
                DBGrid1.Canvas.Brush.Color := clBlue;  
              end;  
            end  
            else begin  
              if dgAlwaysShowSelection in DBGrid1.Options then begin  
                if gdSelected in state then begin  
                  DBGrid1.Canvas.Font.Color := clBlue;  
                end  
                else begin  
                  DBGrid1.Canvas.Brush.Color := clRed;
                end;  
              end  
              else begin  
                DBGrid1.Canvas.Brush.Color := clRed;  
              end;  
            end;


end;


Leider Passiert NIX :?:
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.04.05 12:45 
Du musst DefaultDrawing im Grid ausschalten. Sorry, hatte ich vergessen. Die Komponente kümmert sich da selbst drum.
dragonlord Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 12:59 
Leider funktioniert das nicht.
Ich sehe dann die Einträge nicht mehr. Ist alles weiss.

Habe aber etwas herausgefunden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
If (DataCol = 1) Then 
    Begin
      DBGrid1.Canvas.Brush.Color := clRed;
      DBGrid1.Canvas.FillRect(Rect);
    end;


end;


Da bin ich schon mal auf dem Richtigen Weg. So wie ich das haben will. Er färbt so
alle jede erste Zelle ein. Leider Wird auch der Text überschrieben.
Ich müsste es nur noch hinbekommen das der Text zu sehen ist dann wäre es perfekt.
:?:
dragonlord Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40

Win XP - SP2
D7 Ent.
BeitragVerfasst: Fr 08.04.05 13:10 
OK. Habe es hinbekommen.
Trotzdem danke für die Hilfe. Ich schaue mir die Kompo mal an wenn ich die Vollversion habe.

Für alle die es interessiert hier der Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
If (DataCol = 1) Then Begin
      DBGrid1.Canvas.Brush.Color := clRed;
      DBGrid1.Canvas.FillRect(Rect);
      DBGrid1.Canvas.Font.Color := clWhite;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;


Gruss
Dragonlord
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 08.04.05 13:17 
Das muss am Wochenende liegen. Habe folgende abschließende Zeile vergessen:
ausblenden Delphi-Quelltext
1:
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);					

Nachdem man die Farben gesetzt hat, muss diese Anweisung natürlich folgen.
Und DefaultDrawing wird von der Komponente nicht verändert. Demnach sollte das auf true bleiben. Ist leider ein bisschen her, dass ich mich um diese Basis-Routine in der Komponente gekümmert habe.

Wenn du deinen Wege weiter verfolgen willst, musst du noch ein TextOut machen.

//EDIT:
zu spät. Hast das Problem selbst gelöst. Bravo.