First the TKGridCellPainter.DrawCellFocus method should have the logic that decides if it SHOULD paint moved to a separate check, ie. was:
procedure TKGridCellPainter.DrawCellFocus(const ARect: TRect; SkipTest: Boolean);
begin
if (gdFocused in FState) and (SkipTest or (FGrid.Options * [goRangeSelect, goRowSelect,
goDrawFocusSelected] = [goDrawFocusSelected])) then
begin
// to ensure coming DrawFocusRect will be painted correctly:
SetBkColor(FCanvas.Handle, $FFFFFF);
SetTextColor(FCanvas.Handle, 0);
FCanvas.DrawFocusRect(FCellRect);
end;
end;
change to:
function TKGridCellPainter.ShouldDrawFocus(): Boolean;
begin
Result:=(gdFocused in FState) and (FGrid.Options * [goRangeSelect, goRowSelect,
goDrawFocusSelected] = [goDrawFocusSelected]);
end;
procedure TKGridCellPainter.DrawCellFocus(const ARect: TRect; SkipTest: Boolean);
begin
if (ShouldDrawFocus() or SkipTest) then
begin
// to ensure coming DrawFocusRect will be painted correctly:
SetBkColor(FCanvas.Handle, $FFFFFF);
SetTextColor(FCanvas.Handle, 0);
FCanvas.DrawFocusRect(ARect); // note the use of ARect parameter and not the FCellRect
end;
end;
And the "hard-coded" call in TKCustomGrid.PaintToCanvas can be replaced (to allow the custom drawing to function) from this:
// draw a focus rectangle around cells in goRangeSelect and goRowSelect mode
if not (csDesigning in ComponentState) and (goDrawFocusSelected in FOptions) and
(FOptions * [goRangeSelect, goRowSelect] <> []) and Focused and not EditorMode then
begin
// to ensure coming DrawFocusRect will be painted correctly:
SetBkColor(DC, $FFFFFF);
SetTextColor(DC, 0);
ACanvas.DrawFocusRect(SelectionRect);
end;
to this:
// draw a focus rectangle around cells in goRangeSelect and goRowSelect mode
if not (csDesigning in ComponentState) and (goDrawFocusSelected in FOptions) and
(FOptions * [goRangeSelect, goRowSelect] <> []) and Focused and not EditorMode then
begin
CellPainter.Canvas:=ACanvas;
CellPainter.DrawCellFocus(SelectionRect, True);
end;
First the TKGridCellPainter.DrawCellFocus method should have the logic that decides if it SHOULD paint moved to a separate check, ie. was:
change to:
And the "hard-coded" call in TKCustomGrid.PaintToCanvas can be replaced (to allow the custom drawing to function) from this:
to this: