Is it possible to highlight active row in rStringGridEd?

22 views
Skip to first unread message

grzegorz wisowski

unread,
Sep 27, 2024, 4:07:25 PMSep 27
to Rosi Delphi Components
Hi,

Is it possible to highlight active row in rStringGridEd without checked goRowSelect option? If yes, how to do it?
--
Regards

Tomas Rosinsky

unread,
Sep 30, 2024, 10:45:51 AMSep 30
to Rosi Delphi Components
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:

grzegorz wisowski

unread,
Sep 30, 2024, 2:51:07 PMSep 30
to Rosi Delphi Components
Hi,

With OnSelectCell event it works properly. 
Thanks!
--
Regards
Reply all
Reply to author
Forward
0 new messages