Mega Code Archive

 
Categories / Delphi / ADO Database
 

How to process selected rows in a TDBGrid

Title: How to process selected rows in a TDBGrid function TForm1.Grid_Edit(dbgIn: TDBGrid; qryIn: TQuery): Longint; // declared in the private section begin Result := 0; with dbgIn.DataSource.DataSet do begin First; DisableControls; try while not EOF do begin if (dbgIn.SelectedRows.CurrentRowSelected = True) then begin { +++ Call here the data-processing function +++ zb. iValue := qryIn.FieldByName('FELDNAME').AsInteger; } Inc(Result); end; Next; end; finally EnableControls; end; end; end; procedure TForm1.Button1Click(Sender: TObject); begin Form1.Caption := 'Processed: ' + IntToStr(Grid_Edit(DBGrid1, Query1)); end;