delphi listview filter error

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: delphi listview filter error

Mesaj gönderen mia »

ok i try to do like this

Kod: Tümünü seç

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
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: delphi listview filter error

Mesaj gönderen mrmarman »

think about this point. You not need refresh list if search txt is empty.

You must put that code under the begin which is filtering block.

Kod: Tümünü seç

lvu.Items.BeginUpdate;
lvs.SelectAll;
lvs.CopySelection(LVU);
lvu.Items.EndUpdate;
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: delphi listview filter error

Mesaj gönderen mia »

ops my bad yes you are correct , but still same error after second refresh

Kod: Tümünü seç

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
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: delphi listview filter error

Mesaj gönderen mrmarman »

I cannot see any defect with eye trace. What is wrong on second search?
Resim
Resim ....Resim
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: delphi listview filter error

Mesaj gönderen mia »

not showing searched result , also back space dont show results
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mia
Üye
Mesajlar: 239
Kayıt: 17 Nis 2015 02:18

Re: delphi listview filter error

Mesaj gönderen mia »

i found solve i have to add items in different way than selectall and copy thank you very much mrmarman for the idea
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
in god i trust with every movement i do
graduated student and looking for knowledge
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Re: delphi listview filter error

Mesaj gönderen mrmarman »

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.

Kod: Tümünü seç

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;
Resim
Resim ....Resim
Cevapla