Mega Code Archive

 
Categories / Delphi / VCL
 

Process selected rows in a tdbgrid

eray_ayyildiz@hotmail.com { In the "Object Inspector" set your DBGrid's Option for dgMultiSelect = True. The Grid_Edit function calls for each selected DBGrid-Row a data-processing function. Return value is the number of processed rows. Im Objektinspektor unter Options des DBGrids die Option "dgMultiSelect" auf TRUE setzen. Ruft zu jeder markierten DBGrid-Zeile eine Bearbeitungs-Funktion auf Rückgabewert = Anzahl bearbeiteter Zeilen } function TForm1.Grid_Edit(dbgIn: TDBGrid; qryIn: TQuery): Longint; // declared in the private section // als private deklariert 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 +++ +++ HIER DIE BEARBEITUNGS_FKT AUFRUFEN +++ zb. iValue := qryIn.FieldByName('FELDNAME').AsInteger; und so weiter... } 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;