Mega Code Archive

 
Categories / Delphi / ADO Database
 

Stop the dbgrid control from auto-appending a new entry

{How to stop the dbgrid control from auto-appending a new entry when you move down after the last record in a table. It creates a new blank line / record in the table. Can this be stopped?} {A: Add to your TTables's "BeforeInsert" event the following line:} procedure TForm1.Tbable1BeforeInsert(DataSet: TDataSet); begin Abort; {<<---this line} end; {A: It traps the down key and checks for end-of-file.} procedure TForm8.DBGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Key = VK_DOWN) then begin TTable1.DisableControls; TTable1Next; if TTable1.EOF then Key := 0 else TTable1.Prior; TTable1.EnableControls; end; end;