StringGrid - How to force a selection of a specific cell lazarus / 31-LCL ---------------------------------------------------------------------- maKiaveL · 2010-05-12 17:51 How can I force a selection of a specific cell in StringGrid? For instance, when I run a search I want the first cell to be already selected without having to click. Thank you very much ---------------------------------------------------------------------- theo · 2010-05-12 18:23 This? Code: [Select]StringGrid1.Row:=20; StringGrid1.Col:=5; StringGrid1.SetFocus; ---------------------------------------------------------------------- maKiaveL · 2010-05-12 18:34 No, because that only "set focus" on the cell, doesnt actually select it, since it does not what it's in the OnSelectCell event... ---------------------------------------------------------------------- faber · 2010-05-13 04:35 You can run OnSelectCell manualy Code: [Select]StringGrid1.Row:=20; StringGrid1.Col:=5; StringGrid1SelectCell(self,20,5,cansel); StringGrid1.SetFocus; ---------------------------------------------------------------------- maKiaveL · 2010-05-13 05:24 yeah, that works, thks! ---------------------------------------------------------------------- CM630 · 2025-06-12 11:50 Quote from: faber on May 13, 2010, 06:35:09 amYou can run OnSelectCell manualy Code: [Select]StringGrid1.Row:=20; StringGrid1.Col:=5; StringGrid1SelectCell(self,20,5,cansel); StringGrid1.SetFocus; What is StringGrid1SelectCell(self,20,5,cansel); ? I tried StringGrid1.SelectCell but there is no SelectCell property. ---------------------------------------------------------------------- wp · 2025-06-12 13:24 Quote from: CM630 on June 12, 2025, 01:50:43 pmWhat is StringGrid1SelectCell(self,20,5,cansel); ? The user-provided handler for the OnSelectCell event of the grid. ---------------------------------------------------------------------- etrusco · 2025-06-12 15:38 (deleted, wrong instructions) ---------------------------------------------------------------------- CM630 · 2025-06-13 05:50 I did: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TfrmMain.sgFavouritesSelectCell(Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean);begin end; procedure TfrmMain.popmFavChangeContentClick(Sender: TObject);var  dummy : Boolean;begin  sgFavourites.Options := sgFavourites.Options + [goEditing];  sgFavourites.Col := 1;  sgFavourites.Row := 11;  sgFavourites.OnSelectCell(sgFavourites,1,11,dummy);  sgFavourites.SetFocus;end;  I do not see sgFavourites.OnSelectCell(sgFavourites,1,11,dummy); doing anything. What I need is to set cell [1,11] in editing mode (to start editing it - the cursor is shown, just like as I have clicked on it). Any idea how to do it? ---------------------------------------------------------------------- etrusco · 2025-06-13 16:20 This seems enough for me: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     sgFavourites.ColRow := Point(1, 11);    sgFavourites.SetFocus;    sgFavourites.EditorMode:=true; You only need sgFavourites.Options := sgFavourites.Options + [goEditing]; if you previously disabled it for some other reason. You may also want to call sgFavourites.ClearSelections; to tidy the screen. If you use option goAlwaysShowEditor you don't even need to toggle EditorMode, but there are downsides of course. AFAICT you shouldn't invoke OnSelectCell. It's already triggered even if the selection is changed non-interactively. PS. Sorry for the previous unthoughtful reply ---------------------------------------------------------------------- CM630 · 2025-06-14 21:03 Quote from: etrusco on June 13, 2025, 06:20:30 pmThis seems enough for me: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     sgFavourites.ColRow := Point(1, 11);    sgFavourites.SetFocus;    sgFavourites.EditorMode:=true;... I tried it, it seems to do exactly what I want (still I have not tried it in the real app). Edit: It works in the real app, too.