[SOLVED] How to filtering a grid with an editbox lazarus / 16-Databases ---------------------------------------------------------------------- dquinter · 2017-08-03 19:05 Hello everyone, I’m new to Lazarus (And Pascal) and i think i have an easy problem, but since I’m new, I have no idea how to fix it. I’m trying to make an application for a database made in Firebird, so I have a TZConnection (I'm using Zeos), my TZQuery, which is a select * from table, and my TDataSource linked to my TZQuery. My problem is filtering of a grid with the help of an editbox. I want to filter the grid, with what I type into the editbox, so when I type in someting like "LAZ", the grid only shows the records with "LAZ" in the field I’m searching in, foe example, a record with LAZARUS in the text. So I’m thinking of an onchange event for the editbox, but after that I’m lost. Please help. ---------------------------------------------------------------------- mangakissa · 2017-08-04 06:35 sourcecode could be handly. How do you filter your dbgrid (actually dataset) in your code. Do you recall the query with a where clause or with the property filter? ---------------------------------------------------------------------- balazsszekely · 2017-08-04 08:11 @dquinter QuoteHello everyone, I’m new to Lazarus (And Pascal) and i think i have an easy problem, but since I’m new, I have no idea how to fix it. I’m trying to make an application for a database made in Firebird, so I have a TZConnection (I'm using Zeos), my TZQuery, which is a select * from table, and my TDataSource linked to my TZQuery. My problem is filtering of a grid with the help of an editbox. I want to filter the grid, with what I type into the editbox, so when I type in someting like "LAZ", the grid only shows the records with "LAZ" in the field I’m searching in, foe example, a record with LAZARUS in the text. So I’m thinking of an onchange event for the editbox, but after that I’m lost. 1. Create OnChange event for the Edit 2. Create OnFilterRecord event for the Query 3. Don't forget to change "YOURFIELD" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Change(Sender: TObject);begin  if Trim(Edit1.Text) <> '' then  begin    if not SQLQuery1.Filtered then      SQLQuery1.Filtered := True;    SQLQuery1.Refresh;  end  else    SQLQuery1.Filtered := False;end; procedure TForm1.SQLQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);begin  Accept := Pos(UpperCase(Edit1.Text), UpperCase(DataSet.FieldByName('YOURFIELD').AsString)) > 0;end; ---------------------------------------------------------------------- fiazhnd · 2017-08-05 14:59 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.EditSearchChange(Sender: TObject);begin if EditSearch.Text='' then SQLQuery1.Filtered:=false else begin   SQLQuery1.Filtered:=false;    SQLQuery1.Filter:=' Name LIKE '+ QuotedStr('*'+EditSearch.Text+'*') +                     'OR CName LIKE '+ QuotedStr('*'+EditSearch.Text+'*') +                     'OR City LIKE '+ QuotedStr('*'+EditSearch.Text+'*')+                     'OR Phone LIKE '+ QuotedStr('*'+EditSearch.Text+'*')+                   'OR Car LIKE '+ QuotedStr('*'+EditSearch.Text+'*');  SQLQuery1.Filtered:=true; end; end; ---------------------------------------------------------------------- dquinter · 2017-08-11 18:56 Quote from: mangakissa on August 04, 2017, 08:35:11 amsourcecode could be handly. How do you filter your dbgrid (actually dataset) in your code. Do you recall the query with a where clause or with the property filter? I did someting like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   procedure TfrmClientes.btnBuscarClick(Sender: TObject);  begin    DClientes.Close;    DClientes.SQL.Clear;    DClientes.SQL.Add('select * from CLIENTES');    DClientes.SQL.Add('where upper(NOME) like :BUSCAR');    DClientes.SQL.Add('order by NOME');    DClientes.ParamByName('BUSCAR').AsString := UpperCase(Format('%s%s%s',['%', Trim(edtBuscar.Text),'%']));    DClientes.Prepare;    DClientes.Open;  end;  But I'll try the other methods than GetMem and fiazhnd told me. Thanks to all! ---------------------------------------------------------------------- majid.ebru · 2018-03-06 18:49 Quote from: GetMem on August 04, 2017, 10:11:16 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Edit1Change(Sender: TObject);begin  if Trim(Edit1.Text) <> '' then  begin    if not SQLQuery1.Filtered then      SQLQuery1.Filtered := True;    SQLQuery1.Refresh;  end  else    SQLQuery1.Filtered := False;end; procedure TForm1.SQLQuery1FilterRecord(DataSet: TDataSet; var Accept: Boolean);begin  Accept := Pos(UpperCase(Edit1.Text), UpperCase(DataSet.FieldByName('YOURFIELD').AsString)) > 0;end; Hi @GetMem  Thank you for your codes ---------------------------------------------------------------------- Bobito · 2018-10-25 17:36 @GetMem Amazing; just a few lines of code make marvels !!! Where do I have to study to get that far? I am a newbie in Lazarus. I am already using you code. Before I read this thread I had a messy onKeyPress procedure and never got it to work. Thanks a lot. p.s. Again. Where should I study to get that far? ---------------------------------------------------------------------- mangakissa · 2018-10-26 07:50 Quotep.s. Again. Where should I study to get that far?Trying, practising, reading.... ---------------------------------------------------------------------- Bobito · 2019-02-06 21:52 mangakissa you are very rigth !!! Trying, practicing and reading Definitely I have to follow your advice. ---------------------------------------------------------------------- Soner · 2019-02-06 23:06 Quote from: dquinter on August 11, 2017, 08:56:52 pm.... I did someting like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...    DClientes.SQL.Add('where upper(NOME) like :BUSCAR');... ...  @dquinter: you don't need to use upper(NOME) when you define your string fields as collate unicode _ci something like this: Code: SQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i NOME VARCHAR(yourfieldlength) CHARACTER SET UTF8 COLLATE UNICODE_CI,