Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi DBGrid -> Selektierte Zeile Fett (https://www.delphipraxis.net/191840-dbgrid-selektierte-zeile-fett.html)

HolgerCW 24. Feb 2017 11:04

DBGrid -> Selektierte Zeile Fett
 
Hallo zusammen,

wenn ich in dem Ereignis DrawColumnCell folgendes einbaue:

Delphi-Quellcode:
 
 if (gdSelected in State) then
 begin

  DBGrid.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style + [fsBold];
  DBGrid.Canvas.Font.Color := clBlack;
  DBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end
 else
 begin

  DBGrid.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style - [fsBold];
  DBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end;
dann macht er zwar die selektierte Zeile FETT, aber man sieht dahinter auch noch den Text in NICHT FETT.

Was muss ich tuen ?

Gruss

Holger

Der schöne Günther 24. Feb 2017 11:11

AW: DBGrid -> Selektierte Zeile Fett
 
Dein Rect enthält noch "alten" Inhalt, mach erst mal sauber. Z.B:
Delphi-Quellcode:
DBGrid.Canvas.FillRect(Rect).

HolgerCW 24. Feb 2017 11:50

AW: DBGrid -> Selektierte Zeile Fett
 
Hallo,

habe es erweitert:

Delphi-Quellcode:
if (gdSelected in State) then
 begin

  DBG_WorkFlow_GruppenBau.Canvas.FillRect(Rect);
  DBG_WorkFlow_GruppenBau.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style + [fsBold];
  DBG_WorkFlow_GruppenBau.Canvas.Font.Color := clBlack;
  DBG_WorkFlow_GruppenBau.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end
 else
 begin

  DBG_WorkFlow_GruppenBau.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style - [fsBold];
  DBG_WorkFlow_GruppenBau.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end;
.. aber es ändert sich nichts ...

Der DrawingStyle des DBGrids ist auch gdsGradient. Liegt es eventuell daran ?

nahpets 24. Feb 2017 12:23

AW: DBGrid -> Selektierte Zeile Fett
 
Hier mal ein Auszug aus meinem Fundus, der wie gewünscht funktioniert:
Delphi-Quellcode:
procedure TForm1.dbgDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  // Zeile mit dem aktiven Datensatz.
  if (fdID.AsInteger = dbg.Tag) then begin
    dbg.Canvas.Font.Style := [fsBold];
    dbg.Canvas.Brush.Color := clLime;
    dbg.Canvas.Font.Color := clBlack;
    if Copy(fdIP.AsString,1,3) = 'DNS' then begin
      if (State = [gdSelected])
      or (State = [gdSelected..gdFocused]) then begin
        dbg.Canvas.Brush.Color := clNavy;
        dbg.Canvas.Font.Color := clRed;
      end else begin
        dbg.Canvas.Brush.Color := clWhite;
        dbg.Canvas.Font.Color := clNavy;
      end;
    end;
  end else begin
    dbg.Canvas.Font.Style := [];
  end;
  // Sonderbehandlung für den Sendernamen
  if Column.FieldName = 'Sendername' then begin
    if Column.Field.Text = csSenderOhneName then begin
      if (State=[gdSelected])
      or (State=[gdSelected..gdFocused]) then begin
        dbg.Canvas.Brush.Color := clRed;
        dbg.Canvas.Font.Color := clWhite;
      end else begin
        dbg.Canvas.Font.Color := clRed;
      end;
    end else
    if fdSenderName.AsString <> fdSenderTitel.AsString then begin
      if (State=[gdSelected])
      or (State=[gdSelected..gdFocused]) then begin
        dbg.Canvas.Brush.Color := clPurple;
        dbg.Canvas.Font.Color := clWhite;
      end else begin
        dbg.Canvas.Brush.Color := clPurple;
        dbg.Canvas.Font.Color := clYellow;
      end;
    end;
  end else
  // und noch weitere IF-Elsen
  if ...

  end;
  dbg.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(Die fd....As... sind persitente Datenbankfelder.)

MichaelT 24. Feb 2017 13:00

AW: DBGrid -> Selektierte Zeile Fett
 
DefaultDrawing steht vermutlich noch auch true.

Zitat:

Zitat von HolgerCW (Beitrag 1362524)
Hallo,

habe es erweitert:

Delphi-Quellcode:
if (gdSelected in State) then
 begin

  DBG_WorkFlow_GruppenBau.Canvas.FillRect(Rect);
  DBG_WorkFlow_GruppenBau.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style + [fsBold];
  DBG_WorkFlow_GruppenBau.Canvas.Font.Color := clBlack;
  DBG_WorkFlow_GruppenBau.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end
 else
 begin

  DBG_WorkFlow_GruppenBau.Canvas.Font.Style := DBG_WorkFlow_GruppenBau.Canvas.Font.Style - [fsBold];
  DBG_WorkFlow_GruppenBau.DefaultDrawColumnCell(Rect, DataCol, Column, State);

 end;
.. aber es ändert sich nichts ...

Der DrawingStyle des DBGrids ist auch gdsGradient. Liegt es eventuell daran ?


HolgerCW 24. Feb 2017 15:22

AW: DBGrid -> Selektierte Zeile Fett
 
Hallo zusammen,

das war es DefaultDrawing muss auf FALSE

Danke

Gruss

Holger


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:35 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