2008. október 16., csütörtök

How to stop the DBGrid control from auto-appending a new entry

Problem/Question/Abstract:

How can I stop the DBGrid control from auto-appending a new entry?

Answer:

// Torry's Delphi Tips
// Author Damian Gorski
// Listed 24.02.2003
{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;

Nincsenek megjegyzések:

Megjegyzés küldése