1 (edited by agusecc 2020-01-05 12:04:48)

Topic: filter tablegrid by sql query

please help me
I have one project example MVD and i want filter  one tablegrid by other.
when "newrecord" from tablegrid2 and save to database, so next "newrecord again from tablegrid2 same item data not show in tablegrid2.
if all data in tablegrid2 already save in new other database so data in tablegrid2 not view agian

I send example project.

https://www.dropbox.com/s/w0rhxzw6nu96s … N.rar?dl=0

Post's attachments

Attachment icon example.PNG 85.63 kb, 34 downloads since 2020-01-05 

2 (edited by sibprogsistem 2020-01-05 14:58:04)

Re: filter tablegrid by sql query

will this help?

Post's attachments

Attachment icon DBLESSON.7z 3.69 kb, 118 downloads since 2020-01-05 

Re: filter tablegrid by sql query

Hi sibprogsistem
thanks for try help me, but That's not what I meant.

Post's attachments

Attachment icon Capture.PNG 66.91 kb, 36 downloads since 2020-01-05 

Re: filter tablegrid by sql query

procedure frmAddLessonAktive_OnShow (Sender: TObject; Action: string);
var
   iRow ,c: integer;
   sTr:string;
begin
  c := frmstudent.TableGrid1.RowCount - 1;

     for iRow := 0 to c do
         begin
            sTr:=sTr+'lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ;
         end;

  delete(sTr, length(sTr)-4, 4);
  frmAddLessonAktive.TableGrid1.dbFilter:=sTr;
  frmAddLessonAktive.TableGrid1.dbUpdate;

end;
Post's attachments

Attachment icon DBLESSON.7z 4.51 kb, 102 downloads since 2020-01-05 

5 (edited by derek 2020-01-05 19:17:25)

Re: filter tablegrid by sql query

Hi Agusecc,
Does this help you?  (the combobox selection only shows those subjects that have not already been chosen by the specified student).
Regards,
Derek.

Post's attachments

Attachment icon agusecc combobox.zip 339.29 kb, 132 downloads since 2020-01-05 

6 (edited by agusecc 2020-01-06 00:20:16)

Re: filter tablegrid by sql query

thanks you Derek and  Sibprogsistem for give solution. I glad get trik from Derek with combobox.
but mybe i will develop my project with trik Sibprogsistem, It's work as my hope but still there are eror when i add lesson 2 or 3  time
can you fix it again?

Post's attachments

Attachment icon Capture 2.PNG 75.42 kb, 37 downloads since 2020-01-06 

Re: filter tablegrid by sql query

agusecc wrote:

thanks you Derek and  Sibprogsistem for give solution. I glad get trik from Derek with combobox.
but mybe i will develop my project with trik Sibprogsistem, It's work as my hope but still there are eror when i add lesson 2 or 3  time
can you fix it again?

sTr:=sTr+'lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ;

change to

sTr:=sTr+'dblesson.lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ; 

8 (edited by agusecc 2020-01-06 15:36:28)

Re: filter tablegrid by sql query

sTr:=sTr+'lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ;

change to

sTr:=sTr+'dblesson.lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ; 

sibprogsistem,
I try this script but still eror

Post's attachments

Attachment icon eror.PNG 40.63 kb, 35 downloads since 2020-01-06 

9 (edited by sibprogsistem 2020-01-06 16:38:34)

Re: filter tablegrid by sql query

procedure frmAddLessonAktive_OnShow (Sender: TObject; Action: string);
var
   iRow ,c: integer;
   sTr:string;
begin
  sTr:='';
  c := frmstudent.TableGrid1.RowCount - 1;

     for iRow := 0 to c do
         begin
            sTr:=sTr+'dblesson.lesson <> "'+frmstudent.TableGrid1.Cells[0,iRow]+'" AND ' ;
         end;

  delete(sTr, length(sTr)-4, 4);
  frmAddLessonAktive.TableGrid1.dbFilter:=sTr;
  frmAddLessonAktive.TableGrid1.dbUpdate;

end;

Re: filter tablegrid by sql query

thanks you sibprogsistem

that script work 100%, one again thanks you very very much