Recent

Author Topic: checkbox in grid (Kgrid or DBgrid)  (Read 10773 times)

christensen

  • Full Member
  • ***
  • Posts: 127
checkbox in grid (Kgrid or DBgrid)
« on: October 21, 2011, 09:50:10 am »
Hi,

I want to display the boolean field content in checkbox but it doesn't work.
My db engine is Firebird 2.1.3, but what's mean boolean type field?!
Quote
No BOOLEAN field in Firebird?

Boolean field is available since Firebird 3.0.

For versions prior to 3.0, but you have several alternatives:

1. use char(1)
2. use smallint
3. use domains
http://www.firebirdfaq.org/faq12/

I've choose "smallint" type fiels and the values are 0=unchecked, 1=checked
 I've try to use this tutorial http://wiki.lazarus.freepascal.org/Grids_Reference_Page but in my case i don't have this type of event: "DBGrid1UserCheckboxState" only "DBGrid1UserCheckboxBitmap" in DBGRID but in the Kgrid i don't have at all.

The same for delphi tutorial http://delphi.about.com/od/usedbvcl/l/aa082003a.htm

I prefer to solve it for Kgrid if is possible.

Thanks
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

JD

  • Hero Member
  • *****
  • Posts: 1906
Re: checkbox in grid (Kgrid or DBgrid)
« Reply #1 on: October 21, 2011, 02:38:11 pm »
Take a look at the kgriddemolaz example in the \demos directory. It shows how you can embed controls into a KGrid.

http://www.lazarus.freepascal.org/index.php/topic,14929.msg79682.html#msg79682
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

Zoran

  • Hero Member
  • *****
  • Posts: 1949
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: checkbox in grid (Kgrid or DBgrid)
« Reply #2 on: October 21, 2011, 04:13:14 pm »
See the application attached to this post, it uses DBGrid and database employee which you get with firebird installation.
You will see that in application there are two columns named "PAID". It's actually one column, but the grid shows it twice, once with "y" and "n", as it is in underlying database, and once to show you how to use check boxes.

The database "employee" used here you should find in "C:\Program Files\Firebird\Firebird_2_1\examples\empbuild\EMPLOYEE.FDB" if you are on Windows. On Ubuntu, you should install it, see in lower section of this document: http://www.firebirdsql.org/manual/ubusetup.html
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

christensen

  • Full Member
  • ***
  • Posts: 127
Re: checkbox in grid (Kgrid or DBgrid)
« Reply #3 on: October 21, 2011, 09:05:12 pm »
Thanks
@Zoran, the checkbox in DBgrid it work like a charm.

@JD i prefer to use Kgrid instead of DBgrid, until i figure out how can be done, i will use DBgrid.
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

christensen

  • Full Member
  • ***
  • Posts: 127
Re: checkbox in grid (Kgrid or DBgrid)
« Reply #4 on: October 26, 2011, 08:49:17 am »
Ok i found the solution to display the chechbox on Kgrid, but now a new problem have appeared :(
Code: [Select]
procedure TForm1.KDBGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  R: TRect; State: TKGridDrawState);
begin
  KDBGrid1.CellPainter.CheckBox := True;
end;
take a look on the attachment:


EDIT: i had change the picture .... from mistake i've upload the wrong one ....sorry
« Last Edit: October 26, 2011, 12:40:19 pm by christensen »
Lazarus 1.4.4, FPC 2.6.4, Windows 7 64bit, AMD Athlon 7750 black edition, Asus M3N78-CM
Lenovo L540 i7-4702MQ, Windows 10 x64,Lazarus 1.6.2,FPC 3.0

 

TinyPortal © 2005-2018