Topic: [Script] Multiple select records in TableGrid for removing

Multiple select records in TableGrid for removing


procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var
   i,c: integer;
   iColumn: integer;
begin
     iColumn := Form1.GridEmployees.Columns.Count-1; // in last column stored id of record (last column hided)

     c := Form1.GridEmployees.RowCount - 1; // count of records in TableGrid
     for i :=0 to c do
         if Form1.GridEmployees.Selected[i] then // if record selected
            SQLExecute('DELETE FROM employees WHERE id = ' + Form1.GridEmployees.Cells[iColumn, i]); // SQL query for selected record

     Form1.GridEmployees.dbUpdate;
end;

begin
     Form1.GridEmployees.Options := Form1.GridEmployees.Options + goMultiSelect;
end.

Download project:
http://myvisualdatabase.com/forum/misc. … download=1

Dmitry.

Re: [Script] Multiple select records in TableGrid for removing

An another example, how to multiselect items like checkbox.
Download project:

Post's attachments

Attachment icon MultiSelect like CheckBox.zip 6.63 kb, 1168 downloads since 2015-06-18 

Dmitry.

Re: [Script] Multiple select records in TableGrid for removing

DriveSoft wrote:

Multiple select records in TableGrid for removing


procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var
   i,c: integer;
   iColumn: integer;
begin
     iColumn := Form1.GridEmployees.Columns.Count-1; // in last column stored id of record (last column hided)

     c := Form1.GridEmployees.RowCount - 1; // count of records in TableGrid
     for i :=0 to c do
         if Form1.GridEmployees.Selected[i] then // if record selected
            SQLExecute('DELETE FROM employees WHERE id = ' + Form1.GridEmployees.Cells[iColumn, i]); // SQL query for selected record

     Form1.GridEmployees.dbUpdate;
end;

begin
     Form1.GridEmployees.Options := Form1.GridEmployees.Options + goMultiSelect;
end.

This code does not work in MVD version 6.4 in version 6.2 works without any issue. It gives an error message near " ":syntax error on SQLExecute on DELETE FROM employees Where id = .

Can someone help to fix this code for MVD 6.4?

Thanks in advance.

Re: [Script] Multiple select records in TableGrid for removing

Thanks. I've figure it out by myself.

Re: [Script] Multiple select records in TableGrid for removing

vanadu55 wrote:

Thanks. I've figure it out by myself.


What did you do to get it to work?

On a clear disk you can seek forever

Re: [Script] Multiple select records in TableGrid for removing

CDB wrote:
vanadu55 wrote:

Thanks. I've figure it out by myself.


What did you do to get it to work?

It was quite simple, really and it was in another post here in the forum:

procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var
id: integer;
begin
 id := Form1.GridEmployees.dbItemID;
 SQLExecute ('DELETE FROM employees WHERE id = ' + IntToStr(id));

Form1.GridEmployees.dbUpdate;
end;