Recent

Author Topic: Checkbox in TStringGrid  (Read 52655 times)

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Checkbox in TStringGrid
« Reply #15 on: June 10, 2011, 09:36:27 am »
Under Description of editor styles read the section cbsCheckboxColumn. This seems quite simple, you don't have to provide a custom cell editor.
If this built-in editor does not satisfy your needs, use a check box for a custom cell editor. To see how custom cell editor works, there is a nice simple example in your_lazarus_directory/examples/gridexamples/gridcelleditor. This example uses a combo box, you will use check box instead.
There is a nice example how it is done in delphi. Read http://delphi.about.com/od/usedbvcl/l/aa081903a.htm and then http://delphi.about.com/od/usedbvcl/l/aa082003a.htm

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Checkbox in TStringGrid
« Reply #16 on: June 02, 2014, 11:56:05 am »
StringGrid1.Columns.Items[0].ButtonStyle:=cbsCheckboxColumn;
results in exception class 'EListError' ... List index (0) out of bounds.
I have 5 or 6 columns and at least 4 rows.
I see no reason why this is happening?
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Checkbox in TStringGrid
« Reply #17 on: June 02, 2014, 12:04:52 pm »
Quote
I have 5 or 6 columns and at least 4 rows.
There are two approaches how to use columns of a TStringGrid.
The first, simplier, is just to set ColCount.
The second, more sophisticated (and more powerful), is to add columns via property Columns. Only this way you can use ButtonStyle property.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Checkbox in TStringGrid
« Reply #18 on: June 02, 2014, 12:12:51 pm »
The error is not arising from missing columns, but from missing (column) items. Did you try to create the item(s) via the Object Inspector columns editor, or in code?

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Checkbox in TStringGrid
« Reply #19 on: June 02, 2014, 12:22:28 pm »
The error is not arising from missing columns, but from missing (column) items. Did you try to create the item(s) via the Object Inspector columns editor, or in code?
I dragged and dropped the StringGrid on the frame.
I just tried:
   
Code: [Select]
StringGrid1.Cells[3,3]:='3;3';
StringGrid1.Columns.Items[3].ButtonStyle:=cbsCheckboxColumn;
First line is fine, the second one resulted in the same error message.


I will try Blaazen's proposal and report.
Edit: In the IDe object editor, I clicked on columns and I created 5 colums. Now    StringGrid1.Columns.Items[3].ButtonStyle:=cbsCheckboxColumn; works.
Probably I should use 
Code: [Select]
StringGrid1.Cells[3,3]:='3;3';
   If 3 < StringGrid1.VsisibelColCount  then StringGrid1.Columns.Items[3].ButtonStyle:=cbsCheckboxColumn;


Checkboxes were grayed and did not react on clicking on them. I added goEditing:= true to the StringGrid options. Now they are manually checkable, but other cells are also editable. Is it possible to set this behaviour per column/ cell or I have to emulate it some other way (i.e. OnClick will resuts in checking/unchecking?)
« Last Edit: June 02, 2014, 01:13:20 pm by paskal »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Checkbox in TStringGrid
« Reply #20 on: June 02, 2014, 12:33:20 pm »
Quote
For some reason the checkboxes are grayed and do not reqact on clicking on them.
Set goEditing of StringGrid.Options to True in OI.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

CM630

  • Hero Member
  • *****
  • Posts: 1091
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Checkbox in TStringGrid
« Reply #21 on: June 02, 2014, 02:08:44 pm »
 
Quote
For some reason the checkboxes are grayed and do not reqact on clicking on them.
Set goEditing of StringGrid.Options to True in OI.

Now checkboxes are manually checkable, but other cells are also editable, which I do not want. Is it possible to set this behaviour per column/ cell or I have to emulate it some other way (i.e. OnClick will result in checking/unchecking?)

I added some info in the wiki.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Checkbox in TStringGrid
« Reply #22 on: June 02, 2014, 02:53:38 pm »
Quote
Is it possible to set this behaviour per column/ cell ...
Each column has boolean property ReadOnly.
If you need "per cell" then you really would need some hack, maybe OnBeforeSelection, don't know, I never tried that.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018