Recent

Author Topic: StringGrid CheckBox  (Read 5493 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
StringGrid CheckBox
« on: April 17, 2019, 07:39:53 am »
Hi,

This is my 1st trying StringGrid with the checkboxes.

1) See screenshot... Why are all my checkboxes "highlighted blue"
They need to be all Unchecked at prog startup

2) Can't find much info on how to make them all false.

3) how do I check their state so I can save the "checked state" in a file.

Thanks in Advanced.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

ASerge

  • Hero Member
  • *****
  • Posts: 2337
Re: StringGrid CheckBox
« Reply #1 on: April 17, 2019, 08:17:24 am »
1) See screenshot... Why are all my checkboxes "highlighted blue"
They need to be all Unchecked at prog startup

2) Can't find much info on how to make them all false.

3) how do I check their state so I can save the "checked state" in a file.
:)
1) So, we get a crystal ball (usually on forums the developers decided to show the source code, and we should all be clairvoyants). And what we see..., yeah, I knew in the N-th line is := cbGrayed. Fix it.
2) Skip := cbGrayed or explicit := cbUnchecked
3) Get the state and save it to a file

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #2 on: April 17, 2019, 01:31:05 pm »
This is not very helpful.
 :(
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: StringGrid CheckBox
« Reply #3 on: April 17, 2019, 01:37:08 pm »
We all want to help you. But you didn't provide enough information especially the source code.

Please provide the source code, so we can test and inspect it. To do it:
Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #4 on: April 17, 2019, 01:47:12 pm »
We all want to help you. But you didn't provide enough information especially the source code.

Please provide the source code, so we can test and inspect it. To do it:
Create a new folder, copy and paste all the necessary files except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip here.

There is no source code.
What you see is what is done in the properties, out of the box

I tried using code to build the grid, but get the same thing.

I am just wondering if anyone has ever come across this before.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: StringGrid CheckBox
« Reply #5 on: April 17, 2019, 01:52:11 pm »
I thought you have source and too shy to show it.  :D
I believe ASerge thought the same too.

No source code, right.
Gimme some time, I never did it but lets me try.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #6 on: April 17, 2019, 02:19:30 pm »
I found this, but of course problems exist.

Code: Pascal  [Select][+][-]
  1. for i := 0 to 31 - 1 do
  2.     StringGrid2.Rows[i].CheckBox := cbUnChecked;
  3.  

I get error... (on StringGrid2.Rows.CheckBox :=" line (2nd line))
"main.pas(345,25) Error: identifier idents no member "CheckBox""

Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: StringGrid CheckBox
« Reply #7 on: April 17, 2019, 02:28:54 pm »
Here you are:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Dialogs, Grids, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     btnClear: TButton;
  16.     btnSave: TButton;
  17.     StringGrid1: TStringGrid;
  18.     procedure btnClearClick(Sender: TObject);
  19.     procedure btnSaveClick(Sender: TObject);
  20.     procedure FormCreate(Sender: TObject);
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.btnClearClick(Sender: TObject);
  33. var
  34.   i: Integer;
  35. begin
  36.   for i := 1 to StringGrid1.RowCount-1 do
  37.     StringGrid1.Cells[2, i] := '0';
  38. end;
  39.  
  40. procedure TForm1.btnSaveClick(Sender: TObject);
  41. const
  42.   FileName = 'output.txt';
  43. var
  44.   OutputFile: TextFile;
  45.   i: Integer;
  46. begin
  47.   AssignFile(OutputFile, FileName);
  48.   Rewrite(OutputFile);
  49.  
  50.   for i := 1 to StringGrid1.RowCount-1 do
  51.   begin
  52.     Write(OutputFile, StringGrid1.Cells[1, i] + ' = ');
  53.     case (StringGrid1.Cells[2, i] = '1') of
  54.       True:  WriteLn(OutputFile, 'True');
  55.       False: WriteLn(OutputFile, 'False');
  56.     end;
  57.   end;
  58.  
  59.   CloseFile(OutputFile);
  60.  
  61.   ShowMessage('The data has been saved to output.txt');
  62. end;
  63.  
  64. procedure TForm1.FormCreate(Sender: TObject);
  65. begin
  66.   StringGrid1.Options := StringGrid1.Options + [goEditing];
  67. end;
  68.  
  69. end.

You can download the CheckboxGrid.zip for testing.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #8 on: April 17, 2019, 02:43:43 pm »
I did find a sample in the LAZ folder.
In Desgn view the blue boxes are there, but when you run it, they are not.

Yet, in their code thay are not "unchecking all the checkboxes.

I will give your code a try... Get back to you thanks!
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #9 on: April 17, 2019, 02:46:47 pm »
@Handoko.....  How come in your smaple, in DESGN VIEW, your checkboxes DO NOT HAVE that blue square.
Did you set a property someplace in the property grid???
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #10 on: April 17, 2019, 02:50:04 pm »
Your sample is pretty simple. Nothing is done in code to get riid of those blue boxes, so I must not be seeing a setting in the properties dock that turns them off.

I am not going over it with a fine tuned comb.

The "unckecking" all the boxes code is useful...


THANK YOU!!!!
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: StringGrid CheckBox
« Reply #11 on: April 17, 2019, 02:51:02 pm »
@Handoko.....  How come in your smaple, in DESGN VIEW, your checkboxes DO NOT HAVE that blue square.

Because all the data in the second column are "1" or "0". Value other than that will cause gray (or blue).

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #12 on: April 17, 2019, 03:06:07 pm »
Well, my grid has 1 & 0,.

What version of LAZ are you using?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5376
  • My goal: build my own game engine using Lazarus
Re: StringGrid CheckBox
« Reply #13 on: April 17, 2019, 03:07:25 pm »
Lazarus 1.8.4 FPC 3.0.4 GTK2 Ubuntu Mate 64-bit.
« Last Edit: April 17, 2019, 03:10:28 pm by Handoko »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: StringGrid CheckBox
« Reply #14 on: April 17, 2019, 03:11:04 pm »
I am using 2.0 (Win7), waunder if its a bug??

But, if it was, why would all your boxes be unchecked when viewing in 2.0??

Anyway... Your code worked to at least get around what ever is causing the DESIGN view mishap.
I just put this in formCreate, and it works.

THANK YOU SO MUCH, I was up for 2 hours last night trying to find some code or documentation on the grid.
But, of course the LAZ footprint doesn't have great documentation  :)

Code: Pascal  [Select][+][-]
  1. for i := 1 to StringGrid2.RowCount-1 do
  2.     StringGrid2.Cells[3, i] := '0';
  3.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

 

TinyPortal © 2005-2018