Lazarus

Programming => General => Topic started by: pcurtis on February 27, 2021, 03:54:53 pm

Title: [SOLVED] Indicator arrow in StringGrid
Post by: pcurtis on February 27, 2021, 03:54:53 pm
Hi All,
how can I draw the selected row indicator (like in DBGrid) in a stringgrid fixed colomn?

Thanks in advance.
Title: Re: Indicator arrow in StringGrid
Post by: jamie on February 27, 2021, 05:00:51 pm
This is an example of putting some text in the fixed cell..

You can use a Unicode character for a more pronounced look.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  2.   var CanSelect: Boolean);
  3. begin
  4.   with TstringGrid(Sender) do
  5.    Begin
  6.       Cells[0,Row] := ''; // clear this one first because its still sitting on the last row
  7.       Cells[0,ARow] := '>';
  8.    end;
  9. end;                
  10.  


This is a copy and paste from a Delphi app, not sure if this will work in Laz..
Title: Re: Indicator arrow in StringGrid
Post by: winni on February 27, 2021, 06:32:08 pm

You can use a Unicode character for a more pronounced look.


Yes, we are living in UTF-8 times - so use it.

There are
➤ ➪ ⭆ ⭃
and so much more!

Winni
Title: Re: Indicator arrow in StringGrid
Post by: pcurtis on February 27, 2021, 06:44:07 pm
I use Windoze and was thinking more along the lines drawing on the canvas with the API.
There must be a function.

BTW The code works. Thanks.
Title: Re: Indicator arrow in StringGrid
Post by: jamie on February 27, 2021, 07:32:28 pm
You can do the drawCell event
Title: Re: Indicator arrow in StringGrid
Post by: pcurtis on February 27, 2021, 07:42:12 pm
With what
Title: Re: Indicator arrow in StringGrid
Post by: jamie on February 27, 2021, 09:14:44 pm
Hmm
I guess you could use an Image here instead, not sure …

did this from Delphi. Seems to work. You can change the colors or shape as you need.
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
  2.   Rect: TRect; State: TGridDrawState);
  3. begin
  4.  With TStringGrid(Sender),canvas, rect do begin
  5.     if (aRow = Row)and(ACol =0) then
  6.      Begin
  7.        canvas.Pen.color := clRed;
  8.        canvas.Polygon([Point(CenterPoint.x,Top),Point(Right,CenterPoint.Y),
  9.        Point(CenterPoint.X,Bottom-1)]);
  10.        Canvas.Brush.color := clGreen;
  11.        Canvas.FloodFill(CenterPoint.X+1,CenterPoint.Y+1,Pen.Color,fsBorder);
  12.      end;
  13.  end;
  14. end;
  15.  
  16. procedure TForm1.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer;
  17.   var CanSelect: Boolean);
  18. begin
  19.   with TstringGrid(Sender) do  Invalidate; //force an update otherwise it won't paint..
  20. end;                                                                                          
  21.  
Title: Re: Indicator arrow in StringGrid
Post by: pcurtis on February 27, 2021, 11:54:02 pm
Thanks
TinyPortal © 2005-2018