Recent

Author Topic: [Solved] Eliminate SOME grid lines in StringGrid  (Read 287 times)

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 459
    • Double Dummy Solver - free download
[Solved] Eliminate SOME grid lines in StringGrid
« on: December 05, 2020, 02:28:53 am »
It seems like it's all or nothing.  How can I remove the grid lines for just certain cells. The TRect that is provided in OnDrawCell has already been clipped. I want to eliminate the grid lines in the last line of the attached grid. see jpg
« Last Edit: December 05, 2020, 03:58:39 am by bobonwhidbey »
Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

winni

  • Hero Member
  • *****
  • Posts: 2122
Re: Eliminate SOME grid lines in StringGrid
« Reply #1 on: December 05, 2020, 03:01:40 am »
Hi!

Yes : All or Nothing (Nice song by the Small Faces).

To fit your needs you have to

* Set DefaultDrawing of the Grid to false
* Set the GridLineWidth to zero
* In the events you need a StringGrid1DrawCell for the onDrawCell event

And now you have to draw the BackGround, the contents and the grid as you like it. ,You can uses different colors and fonts for different states. Also for a special range concerning rows or cols.

Don't forget while drawing a grid: the left side of  cell is the right side of the left neighbour. Same with the other three sides.

Winni

winni

  • Hero Member
  • *****
  • Posts: 2122
Re: Eliminate SOME grid lines in StringGrid
« Reply #2 on: December 05, 2020, 03:13:36 am »
Hi!

Just found an example for StringGridDrawCell in my sources.

It is from a StringGrid full of UTF8 chars.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid2DrawCell(Sender: TObject; aCol, aRow: Integer;
  2.                 aRect: TRect; aState: TGridDrawState);
  3. const clFlip = $3DB300;
  4.       clFlop = clGreen;
  5.       clSel =  clRed;
  6. var c : TColor;
  7.     dx : integer;
  8.     utf : TUtf8Char;
  9. begin
  10.   if odd (aRow+Acol) then c := clFlip else c := clFlop;
  11.   if gdSelected in aState then c := clSel;
  12.   StringGrid2.Canvas.Brush.Color := c;
  13.   StringGrid2.Canvas.Rectangle(aRect);
  14.   if gdSelected in aState then
  15.      begin
  16.      StringGrid2.Canvas.pen.style := psDash;
  17.      StringGrid2.Canvas.pen.color := clBlue;
  18.      StringGrid2.Canvas.pen.width := 1;
  19.      StringGrid2.Canvas.Rectangle(aRect.left,aRect.Top,aRect.Right-1,aRect.Bottom-1);
  20.      end; // selected
  21.      utf := StringGrid2.cells[aCol,aRow];
  22.      dx := (aRect.Right - aRect.Left - StringGrid2.Canvas.TextWidth(utf)) div 2;
  23.      StringGrid2.Canvas.TextOut(arect.Left+dx,arect.top +4,utf);
  24. end;


Winni
« Last Edit: December 05, 2020, 03:15:10 am by winni »

bobonwhidbey

  • Sr. Member
  • ****
  • Posts: 459
    • Double Dummy Solver - free download
Re: Eliminate SOME grid lines in StringGrid
« Reply #3 on: December 05, 2020, 03:58:05 am »
Perfect....Thanks winni
Win10 64-bit / Lazarus 32-bit 2.0.10 / FPC 3.2.0

 

TinyPortal © 2005-2018