Forum > LCL
[SOLVED] StringGrid colored rows do not change color when being selected
(1/1)
Vodnik:
I have a StringGrid where some rows are colored different.
I use the following procedure for that:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.StringGridPrepareCanvas(Sender: TObject; aCol, aRow: Integer; aState: TGridDrawState);var MyTextStyle: TTextStyle;begin with (Sender as TMyStringGrid) do begin MyTextStyle := Canvas.TextStyle; MyTextStyle.SingleLine := false; // wrap long line in cell MyTextStyle.Wordbreak := True; // break line in cell if linebreak found MyTextStyle.Layout:=tlTop; Canvas.TextStyle := MyTextStyle; if AR[Tag].RowAttr[aRow] then begin Canvas.Brush.Color:=$F1F1F1; Canvas.Font.Color:=$000000; end; end;end;
This works fine, except that rows with color set to gray do not change color when they are selected (blue).
What have I missed?
wp:
You did not check the selected state:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...if (gdSelected in aState) thenbegin Canvas.Brush.Color := clHighlight; Canvas.Font.Color := clHighlightText;end elseif AR[Tag].RowAttr[aRow] thenbegin ...
Vodnik:
Thanks, WP!
Now works fine.
Navigation
[0] Message Index