TMS DBGrid

DigitalNam
DigitalNam used Ask the Experts™
on
Is there a way to accomplish this in the TMS DBGrid?


procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DM.iv_query.FieldByName('Doc_Type').AsString = 'Fax' then
  begin
     DBGrid1.Canvas.Brush.Color:=clWebLightPink;

     DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
If you are referring to TntDBGrid that in the TMS package then yes that's very possible:
procedure TMainForm.TntDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DM.iv_query.FieldByName('Doc_Type').AsString = 'Fax' then
  begin
     TntDBGrid1.Canvas.Brush.Color:=clWebLightPink;
     TntDBGrid1.DefaultDrawColumnCell(Rect, DataCol, TTntColumn(Column), State);
  end;
end;

Open in new window

Author

Commented:
JimyX: I am using the DBAdvGrid from TMS but the problem is it doesn't have the DrawColumnCell event and no DefaultDrawColumnCell property.
Commented:
1.) Download  http://www.tmssoftware.com/DOC/DBADVGRIDSAMPLES.ZIP from http://www.tmssoftware.com/site/gridpack.asp

2.) Unzip

3.) Check sample project ADOSelColor

Use GETCELLCOLOR event...


type
  TForm1 = class(TForm)
    TntDBGrid1: TDBAdvGrid;
    ... 
    procedure TntDBGrid1GetCellColor(Sender: TObject; ARow, ACol: Integer;AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DBAdvGrid1GetCellColor(Sender: TObject; ARow,ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
begin
  if DM.iv_query.FieldByName('Doc_Type').AsString = 'Fax' then
  begin
     ABrush.Color:=clWebLightPink;
  end;
end;

end.

Open in new window

Author

Commented:
Thank you Thommy. Changed it to:
if DBAdvGrid1.Cells[6,ARow] = 'Fax' then ABrush.Color := clWebLightPink;

Now it works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial