Solved

Checkbox to edit DBGrid - On check enable edit (read only mode = false)

Posted on 2004-09-09
14
463 Views
Last Modified: 2010-04-05
Like the subject says....can someone please show me the correct code to do this:

For TCheckBox: on check enable DBGrid1 edit mode (Read only set to false)

Thanks.
0
Comment
Question by:VirtueTech
  • 5
  • 3
  • 2
  • +2
14 Comments
 
LVL 10

Assisted Solution

by:Jacco
Jacco earned 250 total points
ID: 12022972
This would be the way:

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  DBGrid1.ReadOnly := CheckBox1.Checked;
end;

Hook up the OnClick event of a TCheckBox to this code.

The use can still select text in columns but can't edit them when the CheckBox is checked.

Another way is

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  if CheckBox1.Checked then
    DBGrid1.Options := DBGrid1.Options + [dgRowSelect]
  else
    DBGrid1.Options := DBGrid1.Options - [dgRowSelect] + [dgEditing];
end;

(The help file says dgEditing is ignored when rowselect is True, but it is set to false in stead)

The effect is best seen if you set DBGrid.Options.AlwaysShowSelection to True as well

Regards Jacco
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 12023672
another possibility would be to set this on the dataset direct like

begin
  dbgrid1.datasource.dataset.readonly := not checkbox1.checked;
  //checked-> edit allowed, unChecked= edit not allowed
  //if the other direction wished-> remove the not
end;

meikl ;-)
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 250 total points
ID: 12024768
or as he exactly asked:

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
  DbGrid1.ReadOnly := not(TCheckBox(Sender).Checked);
end;

0
 
LVL 3

Expert Comment

by:ThoseBug
ID: 12045574
May be you need checkbox into dbgrid?...i field with boolean values shows like tcheckbox?
0
 

Author Comment

by:VirtueTech
ID: 12055383
Sorry for not replying...thank you everyone for your answers. I'm going to try them out now.
0
 

Author Comment

by:VirtueTech
ID: 12060910
Thanks everyone for your time.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 12061437
? did not jacco give this suggestion (the graded answer) first ?
0
 
LVL 10

Expert Comment

by:Jacco
ID: 12061482
Yeah, well I forgot the not...
0
 

Author Comment

by:VirtueTech
ID: 12066029
Sorry I'm new to this....am I supposed to "split the points"?  If so how...I don't see an option for that. I just read about it but...

0
 

Author Comment

by:VirtueTech
ID: 12066865
Ok...Kretzschmar...unaccept it for me please.

Also...what would be the proper split of points. Give the user Jacco more points? Or give them both equal?

Thanks for your time.
0
 

Author Comment

by:VirtueTech
ID: 12067408
Thanks...just wanted to get an idea of how a proficient EX-EX user used the "split points" procuedure.

0
 
LVL 10

Expert Comment

by:Jacco
ID: 12069733
Thanks VirtueTech!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 94
code issue 8 100
Delphi Seattle: Project Options : Version info for all platforms, all releases? 2 78
Delphi Form ownership 4 73
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now