Forum > Databases

OnDrawColumnTitle, how Can I draw Default?

(1/1)

hamacker:
Hi ALL,
I doing a column 0 as icon, and all others column as default drawing in dbgrid, but I donĀ“t know how I do it. If I would like only personalize column 0 and all others will be default.

procedure TfmBrowse_Almox.Grade_PesquisaDrawColumnTitle(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  buf:Tbitmap;
begin
  with (Sender as TDBGrid) do
   begin
     if DataCol = 0 then
     begin
       buf:=Tbitmap.Create;
       try
         imagelist_colGrids16x16.GetBitmap(_db_dbgrid_iconcol_filtro, buf); // 4 = filtro
         canvas.Draw(
           Rect.CenterPoint.x-(imagelist_colGrids16x16.Width div 2),
           Rect.CenterPoint.y-(imagelist_colGrids16x16.Height div 2),
           buf);
       finally
         buf.Free;
       end;
     end
     else
     begin
       // I would like to DrawColumnTitle as default to other columns, how?
       // there is a DefaultDrawDataCell way for this event?
     end;
   end;
end;

korba812:
Default drawing of column header is done before OnDrawColumnText (and OnDrawColumnCell for data cell) event handlers are called, so if you want to leave cell drawn by default just don't draw anything in your event handler. So your current OnDrawColumnTitle event handler you specified above will work fine.

Nicole:
This will do the DrawColumnCell-Event for you.

The event will go one line by line and there cell by cell
You start by

  with (Sender as TDBGrid) do begin  ....
end;

Within the loop you can select for the columns, e.g.
  if (Column.FieldName='myhHader') then....

If this is the name / number of your first column you can abort the prozess after this.
This means: Every line will draw the cell of the first column and skip the rest of the lines' cells.

If you need a complete code example, pls post again.

Navigation

[0] Message Index

Go to full version