Recent

Author Topic: Turn off String Grid red border of selected cell?  (Read 7977 times)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Turn off String Grid red border of selected cell?
« on: February 14, 2018, 11:42:07 pm »
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][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  2.   aRect: TRect; aState: TGridDrawState);
  3. begin
  4.   With (sender as tstringgrid) Do
  5.   Begin
  6.     if not (grids.gdFixed in aState) then
  7.     begin
  8.       if not (grids.gdSelected in aState) then
  9.       begin
  10.         Canvas.Brush.Color :=$00710000;
  11.       end
  12.       else
  13.       begin
  14.         Canvas.Brush.Color := $002c8d31;
  15.       end;
  16.     end;
  17.     font.color:=ClWhite;
  18.     defaultdrawcell(Acol, Arow, arect, astate);
  19.   end;
  20. end;      
  21.  
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Turn off String Grid red border of selected cell?
« Reply #1 on: February 14, 2018, 11:59:17 pm »
maybe the Pen.Color is what you need?

canvas.Pen.Color := ????

Just a shot ..
The only true wisdom is knowing you know nothing

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Turn off String Grid red border of selected cell?
« Reply #2 on: February 15, 2018, 12:32:57 am »
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); 
« Last Edit: February 15, 2018, 12:34:53 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Turn off String Grid red border of selected cell?
« Reply #3 on: February 15, 2018, 12:44:07 am »
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

  • Hero Member
  • *****
  • Posts: 6091
Re: Turn off String Grid red border of selected cell?
« Reply #4 on: February 15, 2018, 12:53:27 am »
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 ?
« Last Edit: February 15, 2018, 12:55:24 am by jamie »
The only true wisdom is knowing you know nothing

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Turn off String Grid red border of selected cell?
« Reply #5 on: February 15, 2018, 12:56:12 am »
In addition ... what jamie said  :)

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Turn off String Grid red border of selected cell?
« Reply #6 on: February 15, 2018, 12:58:22 am »
Hi Molly & Jamie,

My moded code is
Code: Pascal  [Select][+][-]
  1. With (sender as tstringgrid) Do
  2.   Begin
  3.     canvas.Pen.Width:=1;
  4.     canvas.pen.color:=color;
  5.     if not (grids.gdFixed in aState) then
  6.     begin
  7.       if not (grids.gdSelected in aState) then
  8.       begin
  9.         Canvas.Brush.Color :=$00710000;
  10.       end
  11.       else
  12.       begin
  13.         Canvas.Brush.Color := $002c8d31;
  14.       end;
  15.     end;
  16.     font.color:=ClWhite;
  17.     Canvas.Rectangle(aRect.Left - 1,aRect.Top - 1,aRect.Right +1,aRect.Bottom + 1);
  18.     defaultdrawcell(Acol, Arow, arect, astate);
  19.   end;
  20.  

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.


« Last Edit: February 15, 2018, 01:01:19 am by josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Turn off String Grid red border of selected cell?
« Reply #7 on: February 15, 2018, 01:02:14 am »
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

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Turn off String Grid red border of selected cell?
« Reply #8 on: February 15, 2018, 01:06:22 am »
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
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Turn off String Grid red border of selected cell?
« Reply #9 on: February 15, 2018, 01:34:33 am »
Set the "FocusColor" property to clNone;
it seems to remove it
The only true wisdom is knowing you know nothing

Josh

  • Hero Member
  • *****
  • Posts: 1271
Re: Turn off String Grid red border of selected cell?
« Reply #10 on: February 15, 2018, 01:36:16 am »
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][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  2.   aRect: TRect; aState: TGridDrawState);
  3. begin
  4.   With (sender as tstringgrid) Do
  5.   Begin
  6.     canvas.Pen.Width:=0; // was set to 2 when testing astate
  7.     canvas.pen.color:=color;
  8. //    if (grids.gdFocused in aState) then astate:=astate-[gdFocused];  No Effect
  9.     if not (grids.gdFixed in aState) then
  10.     begin
  11.       if not (grids.gdSelected in aState) then
  12.       begin
  13.         Canvas.Brush.Color :=$00710000;
  14.       end
  15.       else
  16.       begin
  17.         Canvas.Brush.Color := $002c8d31;
  18.       end;
  19.     end;
  20.  
  21.     focuscolor:=Canvas.Brush.Color;
  22.  
  23.     font.color:=ClWhite;
  24.     Canvas.Rectangle(aRect.Left - 1,aRect.Top - 1,aRect.Right +1,aRect.Bottom + 1);
  25.     defaultdrawcell(Acol, Arow, arect, astate);
  26.   end;
  27. end;        
  28.  

Thanks all for your help.. :) :)
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Turn off String Grid red border of selected cell?
« Reply #11 on: February 15, 2018, 01:50:06 am »
but 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

  • Hero Member
  • *****
  • Posts: 1271
Re: Turn off String Grid red border of selected cell?
« Reply #12 on: February 15, 2018, 01:54:05 am »
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.
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Turn off String Grid red border of selected cell?
« Reply #13 on: February 15, 2018, 05:59:09 am »
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

  • Newbie
  • Posts: 3
Re: Turn off String Grid red border of selected cell?
« Reply #14 on: December 22, 2018, 08:57:30 pm »
hi All and hi josh
Quote
I 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;
 

 

TinyPortal © 2005-2018