Move to a specific stringgrid cell lazarus / 31-LCL ---------------------------------------------------------------------- almcneill · 2015-08-10 12:42 Hello, I checked previous posts for this question, and found an answer, but it did not help me much as I do not understand quite as well as the other person did.  So I would like to pose the question, and hopefully it can be explained to me a little better. I am trying to select a specific cell in a stringgrid component, I am able to move to the cell I want through a search routine, but when I try to grab the info from that cell after the search, I get an error as it returns a -1 out of bounds message. I found on another post a solution, yet I am not as educated to follow the answer and make it work properly. Below is what I found: "You can run OnSelectCell manualy" Code: [Select]StringGrid1.Row:=20; StringGrid1.Col:=5; StringGrid1SelectCell(self,20,5,cansel); StringGrid1.SetFocus; I have tried to get this to work to no avail, I am just not up to par enough to understand properly how to make this work.  If anyone would be kind enough to provide some insight for me, it would be greatly appreciated. Thanks, ---------------------------------------------------------------------- howardpc · 2015-08-10 13:11 This little program may give you some ideas. You need to drop a button, edit, label and stringgrid on a a new Lazarus project main form, and name them appropriately. Also generate an OnCreate handler for the form, and an OnClick handler for the button. Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   SysUtils, Forms, Grids, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)     BFindEditText: TButton;     EFindText: TEdit;     Label1: TLabel;     sg: TStringGrid;     procedure BFindEditTextClick(Sender: TObject);     procedure FormCreate(Sender: TObject);   private     function FindCell(aText: string; out aCol, aRow: integer): boolean;   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var   i: integer = 0;   c, r: integer; begin   for c:=0 to sg.ColCount-1 do     for r:=0 to sg.RowCount-1 do       begin         sg.Cells[c, r]:=Format('ID#%d',[i]);         Inc(i);       end; end; procedure TForm1.BFindEditTextClick(Sender: TObject); var   c, r: integer; begin   if FindCell(EFindText.Text, c, r) then     Label1.Caption:=Format('Found cell at %d,%d, content is "%s"',[c,r,sg.Cells[c,r]])   else     Label1.Caption:=Format('Text "%s" not found in grid',[EFindText.Text]); end; function TForm1.FindCell(aText: string; out aCol, aRow: integer): boolean; var   c, r: integer; begin   aCol:= -1;   aRow:= -1;   for c:=0 to sg.ColCount-1 do     for r:=0 to sg.RowCount-1 do       if SameText(sg.Cells[c,r], aText) then         begin           aCol:=c;           aRow:=r;           Exit(True);         end;   Result:=False; end; end. ---------------------------------------------------------------------- almcneill · 2015-08-10 13:54 howardpc: thanks very much for the reply.  Some of the coding that I was attempting was becoming over convoluted and failing miserably.  Your's on the other hand; simple and works great. Much appreciated for your response!