DBGrid font color in Delphi Berlin

0

I'm having trouble changing the text color of the records displayed in DBGgrid in Delphi Berlin (10.1 update 1). When you try to change the font color and turn on italic and bold, all records appear correctly except the selected record that displays the duplicate text, one with the font changes and the other with no change at all. It is worth mentioning that source down is only for testing so it changes the color of all the records in the system there will be situations where this color will be changed or not. Here is a short excerpt of the code and image that illustrates the problem.

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  TDBGrid(Sender).Canvas.Font.Style := [fsItalic, fsBold];
  TDBGrid(Sender).Canvas.Font.Color := clMaroon;

  TDBGrid(Sender).Canvas.FillRect(Rect);
  TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

    
asked by anonymous 17.05.2017 / 21:52

1 answer

0

While posting the question in Delphi Experts, I did not get a satisfactory answer, but I will go through the two solutions found here:

1: Avoid formatting code every time the record is selected. That way duplicate text does not occur because the system does not generate formatted text. Ex:

procedure TForm2.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if gdSelected in State then
    Exit;

  TDBGrid(Sender).Canvas.Font.Style := [fsItalic, fsBold];
  TDBGrid(Sender).Canvas.Font.Color := clMaroon;

  TDBGrid(Sender).Canvas.FillRect(Rect);
  TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

2: The% of the newer Delphis% (I can not remember from which version) has a property called DBGrig that in Berlin comes set with DrawingStyle , this tells the system to generate the DBGrid from According to the Windows theme, with this property the shape of the text displays the error I mentioned. If this property is changed to gdsThemed , DBGird will not follow the Windows theme but will correctly format the contents of your cells.

It is up to you to choose the best form. If there is another way please let me know as I would like to try.

    
19.05.2017 / 19:24