Recent

Author Topic: [SOLVED] StringGrid colored rows do not change color when being selected  (Read 579 times)

Vodnik

  • Full Member
  • ***
  • Posts: 214
I have a StringGrid where some rows are colored different.
I use the following procedure for that:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGridPrepareCanvas(Sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. var
  4.   MyTextStyle: TTextStyle;
  5. begin
  6.   with (Sender as TMyStringGrid) do begin
  7.     MyTextStyle := Canvas.TextStyle;
  8.     MyTextStyle.SingleLine := false;    // wrap long line in cell
  9.     MyTextStyle.Wordbreak := True;    // break line in cell if linebreak found
  10.     MyTextStyle.Layout:=tlTop;
  11.     Canvas.TextStyle := MyTextStyle;
  12.     if AR[Tag].RowAttr[aRow] then begin
  13.       Canvas.Brush.Color:=$F1F1F1;
  14.       Canvas.Font.Color:=$000000;
  15.     end;
  16.   end;
  17. end;
  18.  

This works fine, except that rows with color set to gray do not change color when they are selected (blue).
What have I missed?
« Last Edit: December 03, 2024, 08:23:46 am by Vodnik »

wp

  • Hero Member
  • *****
  • Posts: 12513
Re: StringGrid colored rows do not change color when being selected
« Reply #1 on: December 02, 2024, 11:21:00 pm »
You did not check the selected state:
Code: Pascal  [Select][+][-]
  1. ...
  2. if (gdSelected in aState) then
  3. begin
  4.   Canvas.Brush.Color := clHighlight;
  5.   Canvas.Font.Color := clHighlightText;
  6. end else
  7. if AR[Tag].RowAttr[aRow] then
  8. begin
  9.   ...

Vodnik

  • Full Member
  • ***
  • Posts: 214
Re: [SOLVED] StringGrid colored rows do not change color when being selected
« Reply #2 on: December 03, 2024, 08:26:44 am »
Thanks, WP!
Now works fine.

 

TinyPortal © 2005-2018