CODE
procedure FindGood(var GoodRow : integer;Colonne:integer;Valeur : string;GridVar:TNextGrid;Rowmax : integer;Cond:String);
procedure FindBad(var BadRow : integer;Colonne:integer;Valeur : string;GridVar:TNextGrid;Rowmax : integer;Cond:String);
procedure filtre(colonne:integer;valeur : string;GridVar:TNextGrid; var Rowmax: integer;Cond:String);
procedure TForm1.filtre(colonne: integer; valeur: string; GridVar: TNextGrid; var Rowmax: integer;Cond:String);
var
badrow : integer;
Max : integer;
Oldrow : integer;
GoodRow : integer;
begin
Oldrow:=-2;
badrow:=0;
GoodRow:=-1;
gridvar.BeginUpdate;
FindBad(badrow,colonne,valeur,Grid,Rowmax,cond);
goodrow:=badrow;
//find a good row after the bad row
FindGood(goodrow,colonne,valeur,grid,rowmax,cond);
While badrow<GoodRow do
begin
gridvar.SwapRows(badrow,GoodRow);
FindBad(badrow,colonne,valeur,Grid,Rowmax,cond);
FindGood(GoodRow,colonne,valeur,grid,rowmax,cond);
end;
gridvar.EndUpdate;
rowmax:=badrow;
gridvar.refresh;
end;
procedure TForm1.FindBad(var BadRow: integer; Colonne: integer; Valeur: string; GridVar: TNextGrid; Rowmax: integer;Cond:String);
var
i : integer;
ValeurR : real;
IsvaleurR : boolean;
begin
if GridVar.Columns[colonne].SortType=stnumeric then
begin
IsvaleurR:=true;
ValeurR:=StrToFloat(valeur);
end;
for i:=badrow to RowMax do
begin
badrow:=i;
if IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsFloat<>ValeurR then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsFloat>ValeurR then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsFloat<ValeurR then
exit;
end;
if not IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsString<>valeur then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsString<valeur then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsString>valeur then
exit;
end;
end;
end;
procedure TForm1.FindGood(var GoodRow: integer; Colonne: integer; Valeur: string; GridVar: TNextGrid; Rowmax: integer; Cond: String);
var
i : integer;
ValeurR : real;
IsvaleurR : boolean;
begin
if GridVar.Columns[colonne].SortType=stnumeric then
begin
IsvaleurR:=true;
ValeurR:=StrToFloat(valeur);
end;
for i:=GoodRow+1 to RowMax do
begin
goodrow:=i;
if IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsFloat=ValeurR then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsFloat<ValeurR then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsFloat>ValeurR then
exit;
end;
if not IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsString=valeur then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsString<valeur then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsString>valeur then
exit;
end;
end;
if goodrow=Rowmax then goodrow:=-1;
end;
procedure FindBad(var BadRow : integer;Colonne:integer;Valeur : string;GridVar:TNextGrid;Rowmax : integer;Cond:String);
procedure filtre(colonne:integer;valeur : string;GridVar:TNextGrid; var Rowmax: integer;Cond:String);
procedure TForm1.filtre(colonne: integer; valeur: string; GridVar: TNextGrid; var Rowmax: integer;Cond:String);
var
badrow : integer;
Max : integer;
Oldrow : integer;
GoodRow : integer;
begin
Oldrow:=-2;
badrow:=0;
GoodRow:=-1;
gridvar.BeginUpdate;
FindBad(badrow,colonne,valeur,Grid,Rowmax,cond);
goodrow:=badrow;
//find a good row after the bad row
FindGood(goodrow,colonne,valeur,grid,rowmax,cond);
While badrow<GoodRow do
begin
gridvar.SwapRows(badrow,GoodRow);
FindBad(badrow,colonne,valeur,Grid,Rowmax,cond);
FindGood(GoodRow,colonne,valeur,grid,rowmax,cond);
end;
gridvar.EndUpdate;
rowmax:=badrow;
gridvar.refresh;
end;
procedure TForm1.FindBad(var BadRow: integer; Colonne: integer; Valeur: string; GridVar: TNextGrid; Rowmax: integer;Cond:String);
var
i : integer;
ValeurR : real;
IsvaleurR : boolean;
begin
if GridVar.Columns[colonne].SortType=stnumeric then
begin
IsvaleurR:=true;
ValeurR:=StrToFloat(valeur);
end;
for i:=badrow to RowMax do
begin
badrow:=i;
if IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsFloat<>ValeurR then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsFloat>ValeurR then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsFloat<ValeurR then
exit;
end;
if not IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsString<>valeur then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsString<valeur then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsString>valeur then
exit;
end;
end;
end;
procedure TForm1.FindGood(var GoodRow: integer; Colonne: integer; Valeur: string; GridVar: TNextGrid; Rowmax: integer; Cond: String);
var
i : integer;
ValeurR : real;
IsvaleurR : boolean;
begin
if GridVar.Columns[colonne].SortType=stnumeric then
begin
IsvaleurR:=true;
ValeurR:=StrToFloat(valeur);
end;
for i:=GoodRow+1 to RowMax do
begin
goodrow:=i;
if IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsFloat=ValeurR then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsFloat<ValeurR then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsFloat>ValeurR then
exit;
end;
if not IsvaleurR then
begin
if cond='EQ' then
if gridvar.Cell[colonne,i].AsString=valeur then
exit;
if cond='INF' then
if gridvar.Cell[colonne,i].AsString<valeur then
exit;
if cond='SUP' then
if gridvar.Cell[colonne,i].AsString>valeur then
exit;
end;
end;
if goodrow=Rowmax then goodrow:=-1;
end;
USAGE :
2 grid : Grid : The data
GridFilter : 4 col(image,combo1,combo2,string) (10 row, or 3,2, 136 as you want)
image to say in graphical way if filter is active or not
combo1.items=header.caption of Grid columns
combo2.item='EQ','INF','SUP'
string for the value
when filter is active
//Multi Filter
max :=pred(grid.RowCount);
for i:=0 to pred(GridFilter.RowCount) do
begin
colonne:=ColonneF.Items.IndexOf(GridFilter.Cell[1,i].AsString);
if GridFilter.Cell[0,i].AsInteger=1 then
filtre(colonne,gridfilter.Cell[2,i].asstring,grid,max,gridfilter.cellbyname['CondF',i].asstring);
end;
i also put this code behind grid.on sort column to sort in the filter