Recent

Author Topic: DBGrid with Checkbox  (Read 2852 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
DBGrid with Checkbox
« on: March 24, 2019, 01:52:30 pm »
Hi,

I've read loads of posts about putting a checkbox in a DBGrid, but I just can't seem to get it to work for me, must be a simple problem, but just can't see it.

I have an MS Access database connected to a DBGrid (through the normal means!) and I've got a column attached to a Yes/No field in the DB. I've set the column button style to cbsCheckboxColumn, but all I get in the grid is the string true/false. Do I have to resort to drawing my own checkbox using the DBGrid1DrawColumnCell approach or could there be something simple I've forgotten to do?

Thanks in advance
Dave
« Last Edit: March 24, 2019, 06:23:40 pm by daveinhull »
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

MichaelBM

  • New Member
  • *
  • Posts: 38
Re: DBGrid with Checkbox
« Reply #1 on: March 24, 2019, 02:22:02 pm »
In design time: Doubleclick your DBGrid and add all the fields.

Select the field you want to be displayed as checkbox.

In Properties (Object Inspector)  find
- ValueChecked
- ValueUnChecked

Set the values according to your needs.
Development Tool: Lazarus 2.0.6 + FPC 3.0.4
Database: Firebird 2.5.7
Operating System: Windows 10 Pro 64-bit

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: DBGrid with Checkbox
« Reply #2 on: March 24, 2019, 02:36:09 pm »
Hi MichaelIBM,

Yes that is exactly what I've done, but the DBGrid just shows true/false, not a checkbox.

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

MichaelBM

  • New Member
  • *
  • Posts: 38
Re: DBGrid with Checkbox
« Reply #3 on: March 24, 2019, 05:04:51 pm »
Did you set the field's property ButtonStyle to "cbsCheckboxColumn" ?
Development Tool: Lazarus 2.0.6 + FPC 3.0.4
Database: Firebird 2.5.7
Operating System: Windows 10 Pro 64-bit

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: DBGrid with Checkbox
« Reply #4 on: March 24, 2019, 05:20:41 pm »
Yes
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11855
Re: DBGrid with Checkbox
« Reply #5 on: March 24, 2019, 05:46:29 pm »
In the attachment I am posting an excerpt of an Access db as used by tvplanit. It displays boolean fields with checkboxes in the dbgrid without doing anything explicitly. Did you create the boolean fields correctly? The demo contains also the code how the fields in the provided mdb file were created.

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: DBGrid with Checkbox
« Reply #6 on: March 24, 2019, 06:23:21 pm »
Many thanks @wp,

Found it and I suspected a simple error.
I'd somehow unchecked the dgeCheckboxColumn in OptionsExtra %)

Thanks again
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018