procedure TForm1.txtFilterChange(Sender: TObject);
var
i1, i2: integer;
s1: string;
b1: boolean;
begin
if txtFilter.Text = '' then
begin
lvu.Items.BeginUpdate;
lvs.SelectAll;
lvs.CopySelection(LVU);
lvu.Items.EndUpdate;
lvs.Visible:= true;
LVU.Visible := False;
end else
begin
lvs.Visible:= False;
LVU.Visible := True;
s1:= LowerCase(txtFilter.text);
LVU.items.beginupdate;
for i1:= LVU.items.count- 1 downto 0 do begin
b1:= pos(s1, LowerCase(LVU.items[i1].caption)) > 0;
if not b1 then for i2:= 0 to LVU.items[i1].subitems.count- 1 do begin
if pos(s1, LVU.items[i1].subitems[i2])> 0 then begin
b1:= true;
break;
end;
end;
if not b1 then
LVU.items.delete(i1);
end;
LVU.items.endupdate;
end;
end;
but still buggy after second search
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ in god i trust with every movement i do graduated student and looking for knowledge
procedure TForm1.txtFilterChange(Sender: TObject);
var
i1, i2: integer;
s1: string;
b1: boolean;
begin
if txtFilter.Text = '' then
begin
lvs.Visible:= true;
LVU.Visible := False;
exit;
end else
begin
lvu.Items.BeginUpdate;
lvs.SelectAll;
lvs.CopySelection(LVU);
lvu.Items.EndUpdate;
lvs.Visible:= False;
LVU.Visible := True;
s1:= LowerCase(txtFilter.text);
LVU.items.beginupdate;
for i1:= LVU.items.count- 1 downto 0 do begin
b1:= pos(s1, LowerCase(LVU.items[i1].caption)) > 0;
if not b1 then for i2:= 0 to LVU.items[i1].subitems.count- 1 do begin
if pos(s1, LVU.items[i1].subitems[i2])> 0 then begin
b1:= true;
break;
end;
end;
if not b1 then
LVU.items.delete(i1);
end;
LVU.items.endupdate;
end;
end;
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ in god i trust with every movement i do graduated student and looking for knowledge
My bus stopped for a break and I had the opportunity to open my notebook.
Also forgatten LowerCase funstion for subitems search.
The corrected the code below.
procedure TForm1.txtFilterChange(Sender: TObject);
procedure ListViewCopy( LvSource, LvTarget : TListView );
var
i, j : Integer;
begin
LvTarget.Items.Clear;
for i := 0 to LvSource.Items.Count - 1 do
begin
With LvTarget.Items.Add do
begin
Caption := LvSource.Items[i].Caption;
for j := 0 to LvSource.Items[i].SubItems.Count - 1
do LvTarget.Items[i].SubItems.Add( LvSource.Items[i].SubItems[j] );
end;
end;
end;
Var
i1, i2 : Integer;
s1 : String;
b1 : Boolean;
begin
if txtFilter.Text = '' then
begin
LVS.Visible := True;
LVU.Visible := NOT LVS.Visible;
end else
begin
LVS.Visible := False;
LVU.Visible := NOT LVS.Visible;
// always refresh before filter
ListViewCopy( LVS, LVU );
s1:= LowerCase(txtFilter.text);
LVU.items.beginupdate;
for i1:= LVU.items.count- 1 downto 0 do
begin
b1:= pos(s1, LowerCase(LVU.items[i1].caption)) > 0;
if not b1 then for i2:= 0 to LVU.items[i1].subitems.count- 1 do begin
if pos(s1, LowerCase(LVU.items[i1].subitems[i2]))> 0 then begin
b1:= true;
break;
end;
end;
if not b1 then
LVU.items.delete(i1);
end;
LVU.items.endupdate;
end;
end;