1 (edited by prahousefamily 2016-08-10 03:11:11)

Topic: CheckBox In TableGrid : How To Select By Check ???

I try add checkbox in tablegrid same add image in tablegrid
----
OK It work can multi check ,uncheck  in tablegrid


After Add Checkbok In Tablegrid I try edit script select tablegrid and display in memo1

    begin
        for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if   Form1.TableGrid1.Selected[i] = true then
        Form1.Memo1.Lines.add('Select Row  '+IntToStr(i))
    end;

 

OK It work Perfect!




But I Try add new code for display by  cell[x,y].check = true it error

begin
        for i := 0 to   Form1.TableGrid1.RowCount - 1 do
         if   Form1.TableGrid1.Cell[0,i].Checked = true then
        Form1.Memo2.Lines.add('Select Row  '+IntToStr(i))
    end;

i can't edit script
How To Edit Script .... Help Me Please !!!

Post's attachments

Attachment icon CheckBoxInGrid.zip 3.61 kb, 283 downloads since 2016-08-10 

My Visual Database : I Love You
Easy For Beginner Student For Me

2 (edited by prahousefamily 2016-08-10 03:10:24)

Re: CheckBox In TableGrid : How To Select By Check ???

Screen Short
http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=2258&download=0

Post's attachments

Attachment icon 2016-08-10 10 03 28.png 14.92 kb, 177 downloads since 2016-08-10 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: CheckBox In TableGrid : How To Select By Check ???

Hello prahousefamily


Hoooooo, you are so close to finding the solution :-)



Didn't you get the 'incompatible type' error message ?


OK let's detail the solution.


First thing you should change

Cell[0,i]

to

Cells[0,i]

After doing that, if you try your code, you'll get the error message saying that your string has no property


To correct that, get ride of

.Checked

And finally you'll get the incompatible type error message.


This is because cells[x,y] returns a String type, and you are testing a Boolean condition. Convert your string to bool and you're good :


Your final code looks like :

if StrToBool(Form1.TableGrid1.cells[0,i]) = true then

Have fun !


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

4 (edited by prahousefamily 2016-08-11 06:16:52)

Re: CheckBox In TableGrid : How To Select By Check ???

It Perfect Code !

Thank You Mathias Very Much Happy Happy

procedure Form1_TableGrid1_OnClick (Sender: string);
var
i : integer ;
begin
    Form1.Memo1.clear ;
    begin
        for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if   Form1.TableGrid1.Selected[i] = true then
        Form1.Memo1.Lines.add('Select Row  '+IntToStr(i))
    end;
    Form1.Memo2.clear ;
    begin
        for i := 0 to   Form1.TableGrid1.RowCount - 1 do
        if StrToBool(Form1.TableGrid1.cells[0,i]) = true then
        Form1.Memo2.Lines.add('Select Row  '+IntToStr(i))
    end;
end;
procedure Form1_OnShow (Sender: string; Action: string);
begin
    Form1.TableGrid1.dbSQL := ('select * from sqlite_master');
    Form1.TableGrid1.dbSQLExecute ;
    Form1.TableGrid1.Columns.InsertcheckboxColumn(0);
    Form1.TableGrid1.Columns[0].Header.Caption  := 'checkbox' ;
    Form1.TableGrid1.Options := Form1.TableGrid1.Options + goMultiSelect ;
end;
begin
end.
Post's attachments

Attachment icon CheckBoxInGridFix.zip 3.97 kb, 289 downloads since 2016-08-11 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: CheckBox In TableGrid : How To Select By Check ???

Hello,


Please download latest beta version 2.7
https://www.dropbox.com/s/582unbatehan1 … a.zip?dl=0


I have added some features for your example.



Fixed project:

Post's attachments

Attachment icon CheckBoxInGrid_fixed.zip 4.72 kb, 371 downloads since 2016-08-11 

Dmitry.

6 (edited by prahousefamily 2016-08-11 12:37:14)

Re: CheckBox In TableGrid : How To Select By Check ???

More Great  have New Property  in Component and New Function


Little Question I will know function  How To use ???
http://myvisualdatabase.com/forum/misc. … mp;preview

Post's attachments

Attachment icon 2016-08-11 18 57 23.png 37.34 kb, 154 downloads since 2016-08-11 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: CheckBox In TableGrid : How To Select By Check ???

prahousefamily wrote:

More Great  have New Property  in Component and New Function


Little Question I will know function  How To use ???
http://myvisualdatabase.com/forum/misc. … mp;preview


InputBox

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    s: string;
begin
    s := InputBox('Caption', 'Enter messave', '');
    ShowMessage('Your message is: ' + s);
end; 

InputQuery

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    s:string;
begin
    if InputQuery('Caption', 'Your message', s) then
    begin
        ShowMessage('Your message is: ' + s);
    end else ShowMessage('User clicked cancel button.');
end;


BeginSQLiteTransaction, CommitSQLiteTransaction
Fast way to insert many records (using transaction), example:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
    SqliteTr: TDBXSqliteTransaction;
    i: integer;
begin
    SqliteTr := BeginSQLiteTransaction;
    for i:= 0 to 10000 do SQLExecute('INSERT INTO employees (lastname) VALUES(''Smith'')');
    CommitSQLiteTransaction(SqliteTr);
end;
Dmitry.

Re: CheckBox In TableGrid : How To Select By Check ???

Hi Dmitry,
Please is it possible to also add a checkbox in the header of the tableGrid for selecting all rows?
Regards

@thezimguy

Re: CheckBox In TableGrid : How To Select By Check ???

Please have a look at this for me
The table rows are numbered according to it's offset and limit.
Everything works well but when you click on search and after that next, it does not function well.

Details
1. Run project
2. Click next button : the numbering will continue from 51 to 100. Also when you change the number of rows per page it works well.
3. Click on search: problem start
4. Click on next : the numbering is not able to continue on clicking next.
Regards

Post's attachments

Attachment icon tGrid.zip 339 kb, 122 downloads since 2019-01-03 

@thezimguy

Re: CheckBox In TableGrid : How To Select By Check ???

thezimguy wrote:

Please have a look at this for me
The table rows are numbered according to it's offset and limit.
Everything works well but when you click on search and after that next, it does not function well.

Details
1. Run project
2. Click next button : the numbering will continue from 51 to 100. Also when you change the number of rows per page it works well.
3. Click on search: problem start
4. Click on next : the numbering is not able to continue on clicking next.
Regards

Still waiting on response to this post.
Thank you in advance.

@thezimguy

Re: CheckBox In TableGrid : How To Select By Check ???

thezimguy wrote:

Hi Dmitry,
Please is it possible to also add a checkbox in the header of the tableGrid for selecting all rows?
Regards

You can place CheckBox on a Form with script

procedure Form1_CheckBox1_OnClick (Sender: TObject);
begin
    if Form1.CheckBox1.Checked then Form1.TableGrid1.SelectAll else Form1.TableGrid1.SelectedRow := -1;
end;
Dmitry.

Re: CheckBox In TableGrid : How To Select By Check ???

thezimguy wrote:

Please have a look at this for me
The table rows are numbered according to it's offset and limit.
Everything works well but when you click on search and after that next, it does not function well.

Details
1. Run project
2. Click next button : the numbering will continue from 51 to 100. Also when you change the number of rows per page it works well.
3. Click on search: problem start
4. Click on next : the numbering is not able to continue on clicking next.
Regards


In the setting of button for search you use column Auto Increment, but in the settings of tablegrid you use column "username", just change Auto Increment to "username" column for the button.

Dmitry.

Re: CheckBox In TableGrid : How To Select By Check ???

DriveSoft wrote:
thezimguy wrote:

Hi Dmitry,
Please is it possible to also add a checkbox in the header of the tableGrid for selecting all rows?
Regards

You can place CheckBox on a Form with script

procedure Form1_CheckBox1_OnClick (Sender: TObject);
begin
    if Form1.CheckBox1.Checked then Form1.TableGrid1.SelectAll else Form1.TableGrid1.SelectedRow := -1;
end;

Thank you so much boss.
Really appreciated.

Again, how do I make all the checkBox in the table checked when I click on the check all.
I mean instead of selecting all the row, the check boxes in each row should be checked and uncheck when I uncheck the check all checkBox
Thanks.

@thezimguy

Re: CheckBox In TableGrid : How To Select By Check ???

Example:

procedure Form1_CheckBox1_OnClick (Sender: TObject);
var
    i: integer;
begin
    for i := 0 to Form1.tGrid.RowCount-1 do
        Form1.tGrid.Cell[0,i].AsBoolean := Form1.CheckBox1.Checked;
end;
Dmitry.