How to highlight rows in DBGrid (RxDBGrid)? lazarus / 16-Databases ---------------------------------------------------------------------- shyub · 2023-12-20 15:36 It is necessary to highlight in color the rows whose "sMas" column has some kind of entry other than a space. Tried several options, but none of them work. Option-1 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.RxDBGrid1GetBtnParams(Sender: TObject; Field: TField;  AFont: TFont; var Background: TColor; var SortMarker: TSortMarker;  IsDown: boolean);begin  if RxDBGrid1.DataSource.DataSet.FieldByName('sMas').AsString<>' ' then  Background:=clLime;end;Option-2 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.RxDBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;  Column: TColumn; AState: TGridDrawState);var  i: Integer;begin//  if(Column.FieldName='sMas')and(Column.Field.AsString<>' ') then begin  if Column.Field.AsString=' ' then begin    for i := 0 to RxDBGrid1.Columns.Count - 1 do begin      RxDBGrid1.Canvas.Brush.Color := clYellow;      RxDBGrid1.Canvas.Font.Color:=clRed;      RxDBGrid1.Canvas.Font.Style:=[fsBold];    end;  end;end;Option-3 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.RxDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;  DataCol: Integer; Column: TColumn; State: TGridDrawState);begin  if TRxDBGrid(Sender).DataSource.DataSet.FieldByName('sMas').AsString<>' ' then          TRxDBGrid(Sender).Canvas.Brush.Color:=clLime;        if gdSelected in State then begin                TRxDBGrid(Sender).Canvas.Brush.Color:= clHighLight;                TRxDBGrid(Sender).Canvas.Font.Color := clHighLightText;        end;      TRxDBGrid(Sender).DefaultDrawColumnCell(Rect,DataCol,Column,State) ;end; ---------------------------------------------------------------------- wp · 2023-12-20 23:27 Look at my attached mini project. It highlights a row when the string in one particular field is longer than a given value. 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.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;  Column: TColumn; AState: TGridDrawState);var  F: TField;  grid: TDBGrid;begin  if Sender is TDBGrid then    grid := TDBGrid(Sender)  else    exit;   F := BufDataset1.FieldByName('Name');  if Length(F.AsString) > SpinEdit1.Value then  begin    if (gdSelected in AState) then    begin      grid.Canvas.Brush.Color := GetShadowColor(clYellow, -10);      grid.Canvas.Font.Color := clRed;  end else      grid.Canvas.Brush.Color := clYellow;  end;end; The OnPrepareCanvas event is executed immediately before a cell is drawn; the brush, pen and font already have been set up for painting. Here is your last chance to modify them. The code checks the contents of that particular field ("Name"). If the length of the string is greater than the predefined value, the grid's Canvas.Brush.Color is set to yellow. This happens for all fields of the current record. --> the entire row becomes yellow, if the Name field contains a sufficiently long string. Otherwise the cells remain as usual. However, I was irritated not seeing the selected cell any more. Therefore, I added a check whether the state of the currently drawn field is selected - in this case the yellow is darkened a bit (by means of the GetShadowColor in unit GraphUtil), and since the white text is hard to read on that still bright background, the font color is set to red. ---------------------------------------------------------------------- shyub · 2023-12-21 05:27 Thank you, it worked with some minor modifications to suit my task. 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.RxDBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;  Column: TColumn; AState: TGridDrawState);var  F: TField;  grid: TRxDBGrid;begin  if Sender is TRxDBGrid then    grid := TRxDBGrid(Sender)  else    exit;  F:=grid.DataSource.DataSet.FieldByName('sMas');  if F.AsString[1]<>' ' then begin    if (gdSelected in AState) then begin      grid.Canvas.Brush.Color := GetShadowColor(clYellow, -10);      grid.Canvas.Font.Color := clRed;    end else      grid.Canvas.Brush.Color := clYellow;  end else    grid.Canvas.Brush.Color := clLime;end;I haven’t chosen the colors yet, the main thing is that it works.