Solved

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

Posted on 2004-09-09
14
456 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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 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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

12 Experts available now in Live!

Get 1:1 Help Now