[SOLVED] TDBGrid - selecting a row based on cell content lazarus / 31-LCL ---------------------------------------------------------------------- phylax · 2015-02-14 12:06 Hi, Is there a way within a program to select a row of a DBGrid component based on the value contained in a particular cell of that row? The value will always be not null and unique. Thanks in advance. ---------------------------------------------------------------------- Zoran · 2015-02-14 12:29 Quote from: phylax on February 14, 2015, 01:06:46 pmHi, Is there a way within a program to select a row of a DBGrid component based on the value contained in a particular cell of that row? The value will always be not null and unique. Thanks in advance. Normally, DBGrid is tied to a DataSet (probably TQuery). Then, you can use DataSet's Locate method. For example, when this:Code: [Select]Query1.Locate('ID', 25, []); gets executed, then DBGrid should position on the row where the field 'ID' has value 25. ---------------------------------------------------------------------- balazsszekely · 2015-02-14 12:32 Hi, dgTest(TDBGrid)-->dsTest(TDataSource)-->qTest(TSQLQuery) If you have a table instead of the query, no problem same applies. Code: [Select]procedure TForm1.Button1Click(Sender: TObject); begin   dgTest.SelectedRows.Clear; //clear all selected rows   qTest.DisableControls; //hide visual feedback, much faster this way on large tables   try     while not qTest.EOF do     begin       if qTest.FieldByName('ID').AsInteger = 10 then //change ID with your unique field       begin         dgTest.SelectedRows.CurrentRowSelected := True;         Break;        end;       qTest.Next;     end;   finally     qTest.EnableControls;   end; end;  If you want multiple rows selected, set dgMultiSelect to True, and remove the break + add multiple if conditions. regards, GetMem ---------------------------------------------------------------------- phylax · 2015-02-15 10:16 Many thanks, Zoran & GetMem. This newbie learned a lot from your replies.