TsWorksheetGrid - Highlight a row when header is clicked lazarus / 49-FPSpreadsheet ---------------------------------------------------------------------- straetch · 2025-09-24 11:43 I want the user to easily follow the same row when scrolling horizontally. The property goRowHighlight works only in the grid itself (I suppose as the worksheetgrid is inherited from TCustomGrid). Clicking on a header does not seem to trigger any event. ---------------------------------------------------------------------- wp · 2025-09-24 13:53 Yes, TsWorksheetGrid is a specialized variant of TCustomGrid, and most of what you can do with TCustomGrid you can do also with TsWorksheetGrid. Highlighting rows: Provider a handler for the OnPrepareCanvas event. Here you can dim or brighten the cell backgrounds in the selected row Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses  GraphUtil; function GrayValue(AColor: TColor): Byte;begin  Result := round((0.3*Red(AColor) + 0.59*Green(AColor) + 0.11*Blue(AColor)));end; procedure TForm1.sWorksheetGrid1PrepareCanvas(Sender: TObject; aCol,  aRow: Integer; aState: TGridDrawState);var  grid: TsWorksheetGrid;  c: TColor;begin  grid := Sender as TsWorksheetGrid;  if (goRowHighlight in grid.Options) and (aRow = grid.Row) then  begin    c := ColorToRGB(grid.Canvas.Brush.Color);    if GrayValue(c) >= 128 then    grid.Canvas.Brush.Color := GetShadowColor(c, -20)    else      grid.Canvas.Brush.Color := GetHighlightColor(c, 50);  end;end; Click on fixed cells: Provider a handler for the OnMouseDown event and move the active cell into the row (or column) of the clicked header cell: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.sWorksheetGrid1MouseDown(Sender: TObject;  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var  grid: TsWorksheetGrid;  C, R: Integer;begin  grid := (Sender as TsWorksheetgrid);  if (Button = mbLeft) and (grid.HeaderCount = 1) then  begin    grid.MouseToCell(X, Y, C, R);    if C = 0 then      grid.Row := R    else if R = 0 then      grid.Col := C;  end;end; ---------------------------------------------------------------------- straetch · 2025-09-24 19:00 I think there is a misunderstanding of the term "header". In the documentation of TCustomGrid the header is a (fixed) row (or column) of the grid itself. I was referring to "header" as in : "ShowHeaders (boolean): can be used to turn off the column and row headers ('A', 'B', 'C', ..., '1', '2', '3')." (ref. FPSpreadsheet wiki). I am looking for a way to highlight a grid row by clicking that header. ---------------------------------------------------------------------- wp · 2025-09-24 21:22 Quote from: straetch on September 24, 2025, 09:00:32 pmI am looking for a way to highlight a grid row by clicking that header. Isn't that what my posted code fragments are doing? The OnPrepareCanvas handler draws the highlighted row in a way that keeps the background colors of the cells, and the OnMouseDown handler moves the active cell into the row of the clicked header so that it is drawn as highlighted. ---------------------------------------------------------------------- straetch · 2025-09-25 12:54 Many thanks. Initially I was using the worksheetgrid click event. But that does not trigger when a header is clicked.