Recent

Author Topic: [SOLVED] Indicator arrow in StringGrid  (Read 1523 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] Indicator arrow in StringGrid
« 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.
« Last Edit: February 27, 2021, 11:54:56 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Indicator arrow in StringGrid
« Reply #1 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..
The only true wisdom is knowing you know nothing

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Indicator arrow in StringGrid
« Reply #2 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

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Indicator arrow in StringGrid
« Reply #3 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.
« Last Edit: February 27, 2021, 06:58:27 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Indicator arrow in StringGrid
« Reply #4 on: February 27, 2021, 07:32:28 pm »
You can do the drawCell event
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Indicator arrow in StringGrid
« Reply #5 on: February 27, 2021, 07:42:12 pm »
With what
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Indicator arrow in StringGrid
« Reply #6 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.  
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Indicator arrow in StringGrid
« Reply #7 on: February 27, 2021, 11:54:02 pm »
Thanks
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018