Recent

Author Topic: Edit checkbox in dbgrid  (Read 6228 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Edit checkbox in dbgrid
« on: August 20, 2014, 09:41:37 pm »
I show data in a dbgrid. I want to add a 'checkbox' column to the dbgrid. Then i want to check / uncheck some rows. From the checked rows i want to retrieve de data from a specific field.

What i got so far is:
Code: [Select]
  TColumn(DBGrid1.Columns.Insert(0)).Title.Caption := 'TESTING'; //create 1 new column: Works fine
  DBGrid1.Columns.Items[0].ButtonStyle:=cbsCheckboxColumn;  //make the new column a  checkbox column : Works fine

The new column is placed in front of the datasource columns.

I can not check / uncheck de new checkboxes.

I tried this. (Doesn't work):
Code: [Select]
  DBGrid1.Columns.Items[0].ReadOnly:=False;
  DBGrid1.ReadOnly:=False;

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Edit checkbox in dbgrid
« Reply #1 on: August 28, 2014, 07:24:53 pm »

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Re: Edit checkbox in dbgrid
« Reply #2 on: August 29, 2014, 09:19:41 pm »
Thanks, it works.

And i get access to a certain field and "export" it to a memo:

export the field ID to a memo from the selected records only:

Code: [Select]
procedure TMain_frm.Button6Click(Sender: TObject);
var
   i: Integer;
begin
  for i := 0 to reclist.Count-1 do  //reclist: see the grid.wiki as mentioned above
    begin
      DBGrid1.DataSource.DataSet.GotoBookmark(Pointer(reclist[I]));
      Memo1.lines.Add (DBGrid1.DataSource.DataSet.FieldByName ('ID').AsString);
    end;
end;

 

TinyPortal © 2005-2018