Problem using image from a TImage list to draw a glyph on to a data cell in DBGrid:
I am putting a bmp image of a "checkmark" in place of the text "Done" in a particular data cell. It works, but there is always black color in the parts of the cell not covered by the image. I have tried enlarging the pixel size of the bmp image to match the cell size, but it always seems to resize the image for me. Using Delphi 10.2, was not problem in D7?
Have tried many combos of setting background colors, pen and brush colors, etc. Here is a simple example of one code attempt:
procedure TFUpRepWS.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with Column do begin
if ((FieldName = 'Done') and (Field.AsString = 'x')) then begin
//below shows black outside of check mark image in the cell
ImageList1.Draw(DBGrid1.Canvas,Rect.Left,Rect.Top,0)
end
else DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
end;
Do the default cell painting DefaultDrawColumnCell always. That will ensure the cell will look like the others. Then draw the image. Try this:
procedure TFUpRepWS.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
with Column do
begin
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
if ((FieldName = 'Done') and (Field.AsString = 'x')) then
ImageList1.Draw(DBGrid1.Canvas, Rect.Left, Rect.Top, 0);
end;
end;
I guess that what you described happens because there is no code that paints the cell background.