?
Solved

how to keep dbgrid in edit mode only?

Posted on 2003-02-21
5
Medium Priority
?
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

800 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