Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-09
14
Medium Priority
?
567 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
12 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
Independent Software Vendors: 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!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

824 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