[SOLVED] DBGrid icon lazarus / 16-Databases ---------------------------------------------------------------------- Pe3s · 2023-06-05 18:51 Hello, how can I put an icon in the DBGrid component in any column? ---------------------------------------------------------------------- dsiders · 2023-06-05 19:04 Quote from: Pe3s on June 05, 2023, 08:51:20 pmHello, how can I put an icon in the DBGrid component in any column? You can use the OnDrawColumnCell event handler (TDrawColumnCellEvent) if it's not a fixed cell. ---------------------------------------------------------------------- Pe3s · 2023-06-06 16:26 Thank you ---------------------------------------------------------------------- Pe3s · 2023-06-10 09:52 Hello, how can I improve the code so that it does not draw bold text in columns? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin   if Column.FieldName = 'Category' then begin      ImageList1.Draw(DBGrid1.Canvas, Rect.Left, Rect.Top, 0)  end;    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end; ---------------------------------------------------------------------- wp · 2023-06-10 11:41 Quote from: Pe3s on June 10, 2023, 11:52:44 amHello, how can I improve the code so that it does not draw bold text in columns? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin   if Column.FieldName = 'Category' then begin      ImageList1.Draw(DBGrid1.Canvas, Rect.Left, Rect.Top, 0)  end;    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end; "does not draw bold text in columns" - if this means: the text in the columns should not be bold, the answer is: Don't add the fsBold style to the DBGrid1.Canvas.Font.Style or DBGrid1.Font.Style - you must be doing this somewhere because this is not default behaviour, but, of course, I don't know where you do this since you do not show this code. If it means: there should not be ANY text in the columns, the answer is: Remove the call to DBGrid1.DefaultDrawColumnCell from above code. ---------------------------------------------------------------------- Pe3s · 2023-06-10 12:00 @wp, I never use bold text. After writing the procedure that draws the icon, it looks like it's superimposing text on top of the text, so it appears thicker ---------------------------------------------------------------------- paweld · 2023-06-10 12:13 Two options: don't add a text drawing call or clear the cell at the beginning of OnDrawCell: https://lazarus- ccr.sourceforge.io/docs/lcl/graphics/tcanvas.fillrect.html ---------------------------------------------------------------------- Pe3s · 2023-06-11 07:19 Thank you ---------------------------------------------------------------------- Pe3s · 2023-06-11 07:46 My solution: DBgrid -> DefaultDraw: False; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);var  LRating: Extended;begin   if Column.FieldName.Equals('Rating') then   begin     LRating := Column.Field.AsInteger;     ImageList1.Draw(DBGrid1.Canvas, Rect.CenterPoint.X - (ImageList1.Width div 2), Rect.CenterPoint.Y - (ImageList1.Height div 2), Trunc(LRating));  end else    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);end;