Recent

Author Topic: TDBGrid Checkbox column allowing only one record to be checked  (Read 1749 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
TDBGrid Checkbox column allowing only one record to be checked
« on: December 22, 2019, 11:02:48 pm »
Platform:  FPC 3.0.4  Lazarus 1.8.4, OS:  Windows Server 2016

Goal:  In a TDBGrid that is displaying data from a Firebird 3x table in the rows, I want each row to have a check box as the first column.  I want all check boxes to be unchecked to start with, and then I want the user to be able to check many, one or none, of the check boxes.

Progress:  I have successfully made a CheckBox column, the user can put a check in the check box of a cell

Snag:  No matter how I work this, only one check box can be checked at a time.  I can check the first check box, but when I check another check box, all other check boxes, including the one I just checked, reverts to either null (grayed with check) or is unchecked.   I want my user to be able to check multiple check boxes (one in each row).  How is this accomplished?  Is there a setting I am missing here?

~~~~~~~~~~~~~~
Tried: 
  Making the check box column a calculated field.  (same unwanted behavior)
  Making a "virtual" field in the SQL that fetches the data  (same unwanted behavior)





valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: TDBGrid Checkbox column allowing only one record to be checked
« Reply #1 on: December 23, 2019, 07:24:23 pm »
Platform:  FPC 3.0.4  Lazarus 1.8.4, OS:  Windows Server 2016

Goal:  In a TDBGrid that is displaying data from a Firebird 3x table in the rows, I want each row to have a check box as the first column.  I want all check boxes to be unchecked to start with, and then I want the user to be able to check many, one or none, of the check boxes.

Progress:  I have successfully made a CheckBox column, the user can put a check in the check box of a cell

Snag:  No matter how I work this, only one check box can be checked at a time.  I can check the first check box, but when I check another check box, all other check boxes, including the one I just checked, reverts to either null (grayed with check) or is unchecked.   I want my user to be able to check multiple check boxes (one in each row).  How is this accomplished?  Is there a setting I am missing here?

~~~~~~~~~~~~~~
Tried: 
  Making the check box column a calculated field.  (same unwanted behavior)
  Making a "virtual" field in the SQL that fetches the data  (same unwanted behavior)
Are using the proprieties "ValueChecked" and "ValueUnchecked" on the Lazarus DBGrid field information?

RedOctober

  • Sr. Member
  • ****
  • Posts: 452
Re: TDBGrid Checkbox column allowing only one record to be checked
« Reply #2 on: December 24, 2019, 12:30:43 am »
I found the answer at:   

https://wiki.freepascal.org/Grids_Reference_Page#Selecting_Records_in_a_DBGrid_using_checkboxes

Scroll way down toward the bottom, section title:  "Selecting Records in a DBGrid using checkboxes"

 

TinyPortal © 2005-2018