Jump to content
Fórum Script Brasil
  • 0

Colorir linha em Dbgrid


Mario Lopes

Question

Olá amigos

Para colorir uma linha de uma dbgrid uso o seguinte código

procedure Tfrmpagamentos.DBGrid1DrawColumnCell(Sender: TObject;

const Rect: TRect; DataCol: Integer; Column: TColumn;

State: TGridDrawState);

begin

ShowScrollBar(dbgrid1.handle, SB_VERT, true);

if query1.FieldByName('estado').AsString='A' then

begin

DBGrid1.Canvas.Brush.Color :=clMenu;

DBGrid1.Canvas.Font.Color := clRed;

DBGrid1.Canvas.FillRect(Rect);

DBGrid1.Canvas.TextOut(Rect.Left+2,Rect.Top,Column.Field.AsString);

//--------

end;

end;

Agora necessito que quando mudo o estado para A o drawcolumncell(..) seja executado para que a linha fique logo com as definições descritas. Como fazê-lo?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

exemplo:

procedure Tfrmpagamentos.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   ShowScrollBar(dbgrid1.handle, SB_VERT, true);

   if (Column.FieldName = 'estado') then
   begin
      if Query1.FieldByName('estado').Value = 'A' then
      begin
         DBGrid1.Canvas.Font.Color := clRed;
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end
      else
      begin
         DBGrid1.Canvas.Font.Color := clBlack;
         DBGrid1.Canvas.FillRect(Rect);
         DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
   end;

end;

avraço

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...