Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-09
14
Medium Priority
?
544 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
[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
  • 5
  • 3
  • 2
  • +2
14 Comments
 
LVL 10

Assisted Solution

by:Jacco
Jacco earned 1000 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 23

Accepted Solution

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

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

0
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.

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
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: …
Suggested Courses

670 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