StringGrid select 2cells and change color lazarus / 31-LCL ---------------------------------------------------------------------- clemmi · 2014-02-10 02:38 How can I select 2 cells in a StringGrid (say 10x10) and change their color (backfround or text) on run time? Just the cells selected, not the entired grid. Not using PrepareCanvas event, just on run time. I  think it uses Rect, draw cell event, etc. but I would like an example code to get started. Thanks! -cl ---------------------------------------------------------------------- Windsurfer · 2014-02-10 08:48 There is a stringgrideditor example, which shows how to do this. I think it is in from 1.0.14. ---------------------------------------------------------------------- howardpc · 2014-02-10 14:12 Here's an example of one way to do what (I think) you want for however many cells are selected, using a popup menu to execute the function. Code: [Select]unit mainColorSelection; {$mode objfpc}{$H+} interface uses   Forms, Graphics, Grids, Menus; type   { TForm1 }   TForm1 = class(TForm)     sg: TStringGrid;     procedure FormCreate(Sender: TObject);     procedure sgBeforeSelection(Sender: TObject; aCol, aRow: Integer);   private     FOriginalSelectedColor: TColor;     FPopup: TPopupMenu;     procedure FPopupClick(Sender: TObject);   end; const   NewSelectedColor = clMoneyGreen; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.sgBeforeSelection(Sender: TObject; aCol, aRow: Integer); begin   if sg.SelectedColor<>FOriginalSelectedColor then     sg.SelectedColor:=FOriginalSelectedColor; end; procedure TForm1.FPopupClick(Sender: TObject); begin   sg.SelectedColor:=NewSelectedColor; end; procedure TForm1.FormCreate(Sender: TObject); var   mi: TMenuItem; begin   FOriginalSelectedColor:=sg.SelectedColor;   FPopup:=TPopupMenu.Create(Self);     mi:=TMenuItem.Create(FPopup);     mi.Caption:='Change colour';     mi.OnClick:=@FPopupClick;     FPopup.Items.Add(mi);   sg.PopupMenu:=FPopup; end; end.