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

delphi listview filter error

Mesaj gönderen mia »

iam try to search for text inside list view with tedit using this code

Kod: Tümünü seç

procedure TForm1.txtFilterChange(Sender: TObject);
var
  i1, i2: integer;
  s1: string;
  b1: boolean;
begin
if txtFilter.Text = '' then Exit;
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;
Code is working perfect but there is problem when i use back space or even delete the searched word , listview become blank and don't show the original results here is my project attached any solve to this problem ?
Dosya ekleri
listview.zip
(68.4 KiB) 100 kere indirildi
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

Hi.

I think (i traced the code with my eyes) if the search text is blank, you must full fill the listview. because list is allready empty, so that;

Kod: Tümünü seç

if txtFilter.Text = '' then Exit;
statement you need a begin / end block to refresh full list like below

Kod: Tümünü seç

if txtFilter.Text = '' then 
begin
   // filling operations of listbox 
   //... 
   Exit;
end;
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 »

searched result is showing but its still don't show the original items after i delete the search word
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

if the LVU listview your master list, you need a backup full list to fresh LVU from.
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 »

yes this is the hard part for me :( i tried to back up the list and combine them with the code sadly i fail , can you help me with that please , what iam trying to achieve is kinda like real time search when i type a word results show up wen back space with one litter result show up when i delete the word actual results shows up
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

you may put your form another listview but invisible state. (visible := false)
Do the same add, delete ext. this shadow listview like LUV listview.
Shadow Listview will be your master list. LUV listview will be for vision.
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 »

can i have little example with coding i getting confused now
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 have an idea, with illusion you may do it an easy way.

You put a shadow listview, for example named SLV with state invisible.
SLV must be the same with, height and location on the form.

if searchtext has any character, then you swap the visibility by LVU.
(LVU. visible := false; SVU. visible := true)
Resim
Resim ....Resim
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'm on the way back to the city I live in and writing from my smartphone.
so keyboard filling a lot of words. when I arrive, i will write an example if you need allready.
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 »

i have to get ride of my current code ? and start from scratch , to think about this logic and coding , will be more helpful if i see example " Coding " to get ride of brain wash .
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

You may be right.
You know yourself the best than the others.
Maybe tidying your code will help you.
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 »

thats what i did so far i added 2 listview and here is my current code

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;
lvs.SelectAll;
lvs.CopySelection(LVU);
end else
begin
LVU.Visible := True;
lvs.Visible:= False;
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;
its kinda work but i cannot show each record after first search when i type mia its shows all results with -M- i need when i do back space with one litter grab resultes of same litters
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

congratulations, you did it.

only change the lvu's with svu's in the filter begin/end block which is deleting items.

(what is the master listview? I gues LVU thing)

oh sorry, SLV is the master. Give me a break, i need to trace
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 »

LVU is the master visible , lvs is the hidden one , still have buggy while searching again
بِسْمِ اللهِ الرَّحْمنِ الرَّحِيمِ
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 »

Yes you're right.
You must refresh the list before filter operations. Because of this backspace and/or delete opetation.

so your code like below.

Kod: Tümünü seç

if txtFilter.Text = '' then
begin
lvs.Visible:= true;
LVU.Visible := False;
end else
begin
// always refresh before filter
lvs.SelectAll;
lvs.CopySelection(LVU);

LVU.Visible := True;
lvs.Visible:= False;
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;
Resim
Resim ....Resim
Cevapla