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

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.
VirtueTechAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ferruccio AccalaiConnect With a Mentor Senior developer, analyst and customer assistance Commented:
or as he exactly asked:

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

0
 
JaccoConnect With a Mentor Commented:
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
 
kretzschmarCommented:
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
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
ThoseBugCommented:
May be you need checkbox into dbgrid?...i field with boolean values shows like tcheckbox?
0
 
VirtueTechAuthor Commented:
Sorry for not replying...thank you everyone for your answers. I'm going to try them out now.
0
 
VirtueTechAuthor Commented:
Thanks everyone for your time.
0
 
kretzschmarCommented:
? did not jacco give this suggestion (the graded answer) first ?
0
 
JaccoCommented:
Yeah, well I forgot the not...
0
 
VirtueTechAuthor Commented:
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
 
VirtueTechAuthor Commented:
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
 
VirtueTechAuthor Commented:
Thanks...just wanted to get an idea of how a proficient EX-EX user used the "split points" procuedure.

0
 
JaccoCommented:
Thanks VirtueTech!
0
All Courses

From novice to tech pro — start learning today.