I'm using Delphi XE2, is there a way to set bold font style on part of the text in DBGrid? For example, when I search for something, I want something like this.

enter image description here

Is it possible to do this?

有帮助吗?

解决方案

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if (Column.Field.FieldName = 'Pay') then
  begin
    if Column.Field.AsString = 'yes' then
    begin
      dbgrid1.Canvas.Font.Color := clBlue;
      dbgrid1.Canvas.Font.Style :=[fsBold];
      dbgrid1.Canvas.FillRect(Rect);
      dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end
    else
    begin
      dbgrid1.Canvas.Font.Color:= clRed;
      dbgrid1.Canvas.FillRect(Rect);
      dbgrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
  end;
end;

其他提示

To solve this problem, set the value of the propertie DefaultDrawing of the DBGrid to False.

I had the same problem for me and solved .

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top