Pregunta

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?

¿Fue útil?

Solución

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;

Otros consejos

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 .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top