Board index » delphi » How make DBGrid cell(Column) looks like Fixed Cell(Column)

How make DBGrid cell(Column) looks like Fixed Cell(Column)

In DBGrid, is there any way to change the first column, so it looks like
fixed column.
I can change the color of background or text using DrawColumnCell, but I
would like the cell looks exactly like fixed cell.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  with Sender as TDBGrid do begin
   if DataCol = 0 then
     Canvas.Brush.Color := clGray;
   DefaultDrawColumnCell(Rect,DataCol,Column,State);
  end;
end;

I tryed:

if DataCol = 0 then
  DefaultDrawColumnCell(Rect,DataCol,Column,[dgFixed])
else
  DefaultDrawColumnCell(Rect,DataCol,Column,State);

It compiles , but it doesn't do anything.

Thanks in advance
Angel

 

Re:How make DBGrid cell(Column) looks like Fixed Cell(Column)


I think I found a way To make this.
Drawback - this is not realy fixed column, it only looks as Fixed

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var TempRec:TRect;
begin
 TempRec:=Rect;
 with Sender as TDBGrid do begin
 if DataCol = 0 then
  with Canvas do begin
   {Fiils Rect with FixedCells Color}
   Brush.Color := clBtnFace;
   FillRect(Rect);
   {Raise Rectangle}
   DrawEdge(Handle, TempRec, BDR_RAISEDINNER, 12);
   DrawEdge(Handle, TempRec,  BDR_RAISEDOUTER, 3);
   {Drow Line using Canvas.Pen}
   Pen.Color := clBlack;
   MoveTo(Rect.Left,Rect.Bottom);
   LineTo(Rect.Right,Rect.Bottom);
   LineTo(Rect.Right,Rect.Top);
   {Write text in rectangle}
   TextOut(Rect.Left+2, Rect.Top+2, Query1.FieldByName('Count').AsString);
    end
  else
  {Default Drawing if it is not First Column}
  DefaultDrawColumnCell(Rect,DataCol,Column,State);
 end;
end;

Other Threads