Select only changed DBGrid rows lazarus / 16-Databases ---------------------------------------------------------------------- cobie1 · 2015-02-25 16:05 Anyone got an idea of how I can simply select the rows in the DBGrid that have changed. I don't want to apply updates to the file I have queried as changes to this file have knock on effects to other files Let's say. for instance, I select the Purchase file and want to change the quantity on one of the records, but changing the purchase quantity also affects the stock amount. What I want to do is select only the rows that have changed and use the info in that row to call a stored procedure to update both the purchase file, the inventory file and possibly other files. Any help is GREATLY appreciated from this newbie. ---------------------------------------------------------------------- LacaK · 2015-03-03 06:09 Do you use TSQLQuery -> TDataSource -> TDBGrid ? May be you can try use something like: 1. OnFilterRecord event handler of TSQLQuery 2. in OnFilterRecord set Accept := SQLQuery1.UpdateStatus = usModified; ---------------------------------------------------------------------- cobie1 · 2015-03-03 08:23 I've found a way to do it by reading through the DBGrid and comparing the new value to the old value (see below), but what I would also like to do is change the colour on the changed field to green if the called procedure returns with 'Success' or red if it is 'Failed', but only once I have read the row and processed it. At the moment I am building a Stringgrid in line with the DBGrid as I read it to show the text 'Updated', 'Failed' or 'Not changed' based on the results. To check for changed values I am using the following:-  DBGrid1.DataSource.DataSet.DisableControls;   for Rcount := 1 to dbgrid1.datasource.dataset.RecordCount do     begin       count := count + 1;       dbgrid1.datasource.dataset.RecNo:=Rcount;       // if SNP value has changed       if DBGrid1.DataSource.DataSet.Fields[2].NewValue <>          DBGrid1.DataSource.DataSet.Fields[2].oldValue then       begin          // Call the stored procedure to update the SNP          srf:=DBGrid1.DataSource.DataSet.Fields[0].AsString;          sqb:=DBGrid1.DataSource.DataSet.Fields[1].AsString;          snp:=DBGrid1.DataSource.DataSet.Fields[2].AsString;          ReturnStatus:='  ';          ChangeSNP(srf, sqb, snp, ReturnStatus);          // Populate the StringGrid to show  the updated rows          if DBGrid1.DataSource.DataSet.Fields[2].NewValue <>          DBGrid1.DataSource.DataSet.Fields[2].oldValue then          begin             Form2.Label5.caption:='Changing colours';             StringGrid1.cells[0, RCount]:='Updated';             StringGrid1.canvas.Brush.color:=clGreen;          end          else          begin             StringGrid1.canvas.Brush.color:=clRed;             StringGrid1.cells[0, RCount]:='Failed';          end;       end;       if DBGrid1.DataSource.DataSet.Fields[2].NewValue =          DBGrid1.DataSource.DataSet.Fields[2].oldValue then       begin         StringGrid1.cells[0, RCount]:='Unchanged';       end;     end;   DBGrid1.DataSource.DataSet.EnableControls;