Forum > Databases

OnDrawColumnTitle, how Can I draw Default?


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);
  with (Sender as TDBGrid) do
     if DataCol = 0 then
         imagelist_colGrids16x16.GetBitmap(_db_dbgrid_iconcol_filtro, buf); // 4 = filtro
           Rect.CenterPoint.x-(imagelist_colGrids16x16.Width div 2),
           Rect.CenterPoint.y-(imagelist_colGrids16x16.Height div 2),
       // I would like to DrawColumnTitle as default to other columns, how?
       // there is a DefaultDrawDataCell way for this event?

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.

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  ....

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.


[0] Message Index

Go to full version