Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how to keep dbgrid in edit mode only?

Posted on 2003-02-21
5
Medium Priority
?
408 Views
Last Modified: 2010-04-04
hi,

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

please help.
0
Comment
Question by:morgantop
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 total points
ID: 7994292
? maybe this way (on Dataset)

procedure TForm1.Table1BeforeInsert(DataSet: TDataSet);
begin
  abort;
end;

procedure TForm1.Table1BeforeDelete(DataSet: TDataSet);
begin
  abort;
end;

you could it also combine into one method
assigned by both events

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7994305
appendix to above

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

meikl ;-)
0
 
LVL 9

Expert Comment

by:mocarts
ID: 7994328
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.
0
 
LVL 1

Author Comment

by:morgantop
ID: 7994670
thanks kretzschmar,
you did it again.

mo, thanks also but he was too fast ;)
0
 
LVL 9

Expert Comment

by:mocarts
ID: 7995042
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question