Recent

Author Topic: Colored cells of a string grid  (Read 7134 times)

MartinK

  • Newbie
  • Posts: 2
Colored cells of a string grid
« on: April 08, 2008, 08:13:11 pm »
Is it possible to give any cell of a string grid a colored background?

OnixJr

  • Full Member
  • ***
  • Posts: 172
    • http://www.brlazarus.kit.net
RE: Colored cells of a string grid
« Reply #1 on: April 08, 2008, 10:53:41 pm »
This code paint a blue background in StringGrid1.Cells[2, 2] (OnPrepareCanvas event):

Code: [Select]

procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  aState: TGridDrawState);
begin
  If ((aCol = 2) and (aRow = 2)) then
    StringGrid1.Canvas.Brush.Color := clBlue;
end;  


Regards,
Júnior
Portal Lazarus Brasil - http://lazaruspascal.codigolivre.org.br/portal.php
Lazarus BOOK (in portuguese) - http://lazarus-book.blogspot.com
<hipernetjr@yahoo.com.br> - Curitiba/Brazil

CM630

  • Hero Member
  • *****
  • Posts: 885
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Colored cells of a string grid
« Reply #2 on: May 16, 2012, 01:12:54 pm »
So if I want to change the background of several cells, does it mean, that I have to store the background colours in an array and to recolour them with a loop each time when the StringGrid is repainted?
Лазар 2,0,6;W7 64bit or XP 32bit;FPC3,2,0;rev 62129

Blaazen

  • Hero Member
  • *****
  • Posts: 2852
  • POKE 54296,15
    • Eye-Candy Controls
Re: Colored cells of a string grid
« Reply #3 on: May 16, 2012, 02:01:39 pm »
No, if you assign OnPrepareCanvas event and your StringGrid has 100 cells then this event is raised 100 times. You don't need any loop.
Lazarus 2.1.0 r63594 FPC 3.3.1 r40507 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/

CM630

  • Hero Member
  • *****
  • Posts: 885
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Colored cells of a string grid
« Reply #4 on: May 16, 2012, 02:34:31 pm »
Ideed, no loop is needed, just
  If aRow> 0 then
      StringGrid1.Canvas.Brush.Color := BG[aCol, aRow];
Лазар 2,0,6;W7 64bit or XP 32bit;FPC3,2,0;rev 62129

Jvan

  • New Member
  • *
  • Posts: 46
Re: Colored cells of a string grid
« Reply #5 on: August 02, 2020, 02:42:02 am »
Ideed, no loop is needed, just
  If aRow> 0 then
      StringGrid1.Canvas.Brush.Color := BG[aCol, aRow];

I have this problem message using your code:
" main.pas(100,36) Error: Identifier not found "BG" "

 

TinyPortal © 2005-2018