There is no easy way to do it. Problem is that this feature is not supported "by design" in TDBGrid.
Main issue is in this part of TCustomDBGrid.DrawCell:
Value := '';
OldActive := FDataLink.ActiveRecord;
try
FDataLink.ActiveRecord := ARow; //<-- after this line, current cell is at current row anyway
if Assigned(DrawColumn.Field) then
Value := DrawColumn.Field.DisplayText;
if HighlightCell(ACol, ARow, Value, AState) and DefaultDrawing then
DrawCellHighlight(ARect, AState, ACol, ARow);
if not Enabled then
Font.Color := clGrayText;
if FDefaultDrawing then
WriteText(Canvas, ARect, 3, 2, Value, DrawColumn.Alignment,
(DrawColumn.BidiMode = bdRightToLeft) and
UseRightToLeftAlignmentForField(DrawColumn.Field, DrawColumn.Alignment));
if Columns.State = csDefault then
DrawDataCell(ARect, DrawColumn.Field, AState); //<-- here we have event
DrawColumnCell(ARect, ACol, DrawColumn, AState); //<-- here we have event
finally
FDataLink.ActiveRecord := OldActive; //<-- after this code, active row at right place again
end;
So when you try to check active row in event it's always return true.
right way to check if current cell is in active row it's:
if OldActive = FDataLink.ActiveRecord then
but OldActive it's local variable so you don't have access to it.
Only way to deal with it - it's make own descendant of TCustomDBGrid and reimplement DrawCell method.