I have a problem in Delphi 10.1 in a multi-device application (on Windows).
I have a StringGrid
(connected to a db) and I can change background color of row, but the problem is there is a "padding" (in grey/silver) between cells.
In onformCreate
I define:
stringgrid1.DefaultDrawing := False;
This is my code:
procedure Tlist_form.StringGrid1DrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var aRowColor: TBrush;
begin
aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
if (stringgrid1.Cells[7,row]='1') then
aRowColor.Color := TAlphaColors.Green
else
aRowColor.Color := TAlphaColors.Red;
Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
aRowColor.free;
end;
In Delphi 6 I've never had this problem, and I don't know how to fix-it. Thank you.
Solution 1 (at design time):
For each
StringColumn
locate thePadding
property and change all values from 3 to 0.Solution 2 (at run time):
Add a
TRectF
to local vars. Assign it the value ofBounds
andInlfate()
it. The modifiedOnDrawColumnCell()
looks like this:The grid looks like this with both solutions:
To also remove the lines between the cells, untick
ColLines
andRowLines
in the gridsOptions
.