Hi,
setting of cell look is easily possible by usage of the event OnGetCellParams where you can set cell properties individually.
So you can also set Highlight according to current row:
procedure TStringGridEdForm.rStringGridEd1GetCellParams(Sender: TObject; Col, Row: Integer; AFont: TFont; var Background: TColor; var Highlight: Boolean);
begin
if Row=rStringGridEd1.Row then Highlight:=true;
end;
Anyway there is one issue with refreshing of cells after selection of the new cell because by default just old cell and new cell is invalidated.
So you have to invalidate also whole old row and new row to ensure update of background by OnSelectCell event (or you can simply invalidate whole grid but it could be slow for large grids with many cells):
procedure TStringGridEdForm.rStringGridEd1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
ARect: TGridRect;
begin
//
myGrid .Invalidate; too slow, invalidate just current and new row
if ARow<>myGrid.Row then
begin
ARect.Left := 0;
ARect.Right :=
myGrid .VisibleColCount+1;
ARect.Top := ARow;
ARect.Bottom := ARect.Top;
myGrid .InvalidateRectEx(ARect);
ARect.Top :=
myGrid .Row;
ARect.Bottom := ARect.Top;
myGrid .InvalidateRectEx(ARect);
end;
end;
I hope it helps.
Regards
Tomas
Dne pátek 27. září 2024 v 22:07:25 UTC+2 uživatel grzegorz wisowski napsal: