Link to home
Start Free TrialLog in
Avatar of morgantop
morgantop

asked on

how to keep dbgrid in edit mode only?

hi,

i would like to prevent users from inserting or deleting (ctrl + del) data in a TDBGrid.

please help.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
appendix to above

you must disable the dgConfirmDelete in the dbgrid.option
to get rid of the ConfirmDeleteMessageBox

meikl ;-)
Avatar of mocarts
mocarts

easiest way is to place abort; in your Table/Query BeforeDelete and BeforeInsert events.

procedure Table1BeforeInsert(DataSet: TDataSet);
begin
  // yoy can optionally check for some flag if you need append/delete record in program
  // if UserEditMode then
  abort;
end;

to prevent for Delete/Insert only within Grid you must catch pressed keys in OnKeyDown event and that is more complex as, for example, TAB key produces row insertion if it is pressed on last editable column in last row etc.

wbr, mo.
Avatar of morgantop

ASKER

thanks kretzschmar,
you did it again.

mo, thanks also but he was too fast ;)
yee, 3 min late :D
I saw your question 1h before, but I had to go to English courses, to polish my writing speed and style :)

good luck!
mo.