Turn off String Grid red border of selected cell? lazarus / 31-LCL ---------------------------------------------------------------------- Josh · 2018-02-14 22:42 I have not used stringgrid in a while, and am trying to remove the red line around a selected cell. I have placed the following in ondraw event I suspect I have forgot to turn off an option somewhere, as last time I used stringgrid ( 3+ years ago) i am sure I did not have this behaviour, and I no longer have the code. 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.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;  aRect: TRect; aState: TGridDrawState);begin  With (sender as tstringgrid) Do  Begin    if not (grids.gdFixed in aState) then    begin      if not (grids.gdSelected in aState) then      begin        Canvas.Brush.Color :=$00710000;      end      else      begin        Canvas.Brush.Color := $002c8d31;      end;    end;    font.color:=ClWhite;    defaultdrawcell(Acol, Arow, arect, astate);  end;end; ---------------------------------------------------------------------- jamie · 2018-02-14 22:59 maybe the Pen.Color is what you need? canvas.Pen.Color := ???? Just a shot .. ---------------------------------------------------------------------- Josh · 2018-02-14 23:32 Hi I have just tried pen.color and pen.width:=0 and still get the red border. Code: [Select]canvas.Pen.Width:=0; canvas.pen.color:=clwhite; Canvas.Rectangle(aRect.Left - 1,aRect.Top - 1,aRect.Right +1,aRect.Bottom + 1); ---------------------------------------------------------------------- molly · 2018-02-14 23:44 did you meant the focus rectangle josh ? You should be able to check for that with gridstate gdFocused and draw according to your wishes (e.g. not draw the focus rectangle). ---------------------------------------------------------------------- jamie · 2018-02-14 23:53 the fact that u r calling the default drawing pretty much negates what you are doing. How about not calling the default drawing if it was a focus rectangle drawing cycle ? ---------------------------------------------------------------------- molly · 2018-02-14 23:56 In addition ... what jamie said ---------------------------------------------------------------------- Josh · 2018-02-14 23:58 Hi Molly & Jamie, My moded code is 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 With (sender as tstringgrid) Do  Begin    canvas.Pen.Width:=1;    canvas.pen.color:=color;    if not (grids.gdFixed in aState) then    begin      if not (grids.gdSelected in aState) then      begin        Canvas.Brush.Color :=$00710000;      end      else      begin        Canvas.Brush.Color := $002c8d31;      end;    end;    font.color:=ClWhite;    Canvas.Rectangle(aRect.Left - 1,aRect.Top - 1,aRect.Right +1,aRect.Bottom + 1);    defaultdrawcell(Acol, Arow, arect, astate);  end;  I would have thought the code would draw a rectangle of pencolor=color of width one, but it does not change anything. If I change the pen width to 6 then still nothing changes, if I comment out the defaultdraw routine then I get a wide border, but still I have a red line around the selected cell. ---------------------------------------------------------------------- molly · 2018-02-15 00:02 if your aim is only to remove the focused rectangle then remove the flag form the drawstate and call defaultdrawcell. That should be able to do the trick without too much additional code. In case you wish to alter more then you would need to add additional checks and draw the cell yourself (at least for those states for which you wish to change drawing). ---------------------------------------------------------------------- Blaazen · 2018-02-15 00:06 Hi, there is public (not published) property FocusColor so you can change the red dotted line to any color. There's also options DrawFocusSelected which fills the cell with color clActiveCaption instead of the line around. Also, there is property UseXORFeatures, which affects focus, see http: //wiki.freepascal.org/Grids_Reference_Page#property_UseXORFeatures.3B ---------------------------------------------------------------------- jamie · 2018-02-15 00:34 Set the "FocusColor" property to clNone; it seems to remove it ---------------------------------------------------------------------- Josh · 2018-02-15 00:36 Hi Molly I added in if (grids.gdFocused in aState) then astate:=astate-[gdFocused]; but this had no effect, debugged the value of astate when it was defaultdrawing and astate had changed, but did not effect result. Hi Blaazen Ading in FocusColor Solved it I will have to look at what other non published properies are available. 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.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;  aRect: TRect; aState: TGridDrawState);begin  With (sender as tstringgrid) Do  Begin    canvas.Pen.Width:=0; // was set to 2 when testing astate    canvas.pen.color:=color;//    if (grids.gdFocused in aState) then astate:=astate-[gdFocused];  No Effect    if not (grids.gdFixed in aState) then    begin      if not (grids.gdSelected in aState) then      begin        Canvas.Brush.Color :=$00710000;    end      else      begin        Canvas.Brush.Color := $002c8d31;      end;    end;     focuscolor:=Canvas.Brush.Color;     font.color:=ClWhite;    Canvas.Rectangle(aRect.Left - 1,aRect.Top - 1,aRect.Right +1,aRect.Bottom + 1);    defaultdrawcell(Acol, Arow, arect, astate);  end;end;       Thanks all for your help.. ---------------------------------------------------------------------- molly · 2018-02-15 00:50 Quote from: josh on February 15, 2018, 01:36:16 ambut this had no effect, debugged the value of astate when it was defaultdrawing and astate had changed, but did not effect result. thanks for the feedback. Hmz... strange i vividly remember that should be able to do the trick. Perhaps i'm remembering wrongly, in which case i'm sorry about guiding your wrongly. ---------------------------------------------------------------------- Josh · 2018-02-15 00:54 Hi Molly, No worries, I agree it should solve it, I have been trying to work out why not, as astate is being changed before the call to defaultdraw. I am using latest svn, not sure if that is having an impact, hopfully not. ---------------------------------------------------------------------- molly · 2018-02-15 04:59 it is my bad Josh. See also wiki. The focus rectangle is drawn after OnDrawCell. And seeing that order of things made my recollection a little better. At least in Delphi it was possible to call DrawFocusRectangle yourself when the state was set. Because of the 'or'-drawing of that rectangle, that rectangle looks to have disappeared when the VCL made the second call to that function. No idea if that also works for LCL (and for every widgetset). ---------------------------------------------------------------------- voltag · 2018-12-22 19:57 hi All and hi josh QuoteI have not used stringgrid in a while, and am trying to remove the red line around a selected cell. ... sGrid: TStringGrid; ... //this string off FocusRect lines sGrid.FocusRectVisible:=false; ---------------------------------------------------------------------- PJW · 2020-11-16 09:13 I know it's a two years after your post, but did you look at FocusColor:     The color used to draw the current focused cell if UseXORFeatures is not set; by default this is clRed. FocusRectVisible   :  Turns on/off the drawing of focused cell. I beleive those two properties will do what you are/were looking for.