whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

88 Visitors Online


 
...process selected rows in a TDBGrid?
Autor: Chr.Rosenkranz
Homepage: http://www.christian-rosenkranz.de
[ Print tip ]  

Tip Rating (7):  
     


{
 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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners