ST3VO
asked on
Code Modification Help Needed
Hi all,
I need some help modifying some code.
The code will basically searches and displays contents on a ListView.
This code works but it only displays the results of the search.
What I need it to do is the display the results of the test (Like it does already) and under that, the rest of the data (Not just the results).
So, if the ListView had 10 rows of data...and the search result was 2 found it will display these results First (It already does that)...and also the 8 rows remaining under that.
Here is the code:
procedure TForm1.ComboBox1Change(Sen der: TObject);
var
i1, i2: integer;
s1: string;
b1: boolean;
begin
s1:= ComboBox1.text; // our search-word
listview1.items.beginupdat e;
for i1:= listview1.items.count- 1 downto 0 do begin
b1:= pos(s1, listview1.items[i1].captio n)> 0;
if not b1 then for i2:= 0 to listview1.items[i1].subite ms.count- 1 do begin
if pos(s1, listview1.items[i1].subite ms[i2])> 0 then begin
b1:= true;
break;
end;
end;
if not b1 then listview1.items.delete(i1) ;
end;
listview1.items.endupdate;
end;
Hope you can help!
Thanks
ST3VO
I need some help modifying some code.
The code will basically searches and displays contents on a ListView.
This code works but it only displays the results of the search.
What I need it to do is the display the results of the test (Like it does already) and under that, the rest of the data (Not just the results).
So, if the ListView had 10 rows of data...and the search result was 2 found it will display these results First (It already does that)...and also the 8 rows remaining under that.
Here is the code:
procedure TForm1.ComboBox1Change(Sen
var
i1, i2: integer;
s1: string;
b1: boolean;
begin
s1:= ComboBox1.text; // our search-word
listview1.items.beginupdat
for i1:= listview1.items.count- 1 downto 0 do begin
b1:= pos(s1, listview1.items[i1].captio
if not b1 then for i2:= 0 to listview1.items[i1].subite
if pos(s1, listview1.items[i1].subite
b1:= true;
break;
end;
end;
if not b1 then listview1.items.delete(i1)
end;
listview1.items.endupdate;
end;
Hope you can help!
Thanks
ST3VO
ASKER
Would using 2 components slow down the process?
not really, how many items are there approx. in the list?
ASKER
This will change ...could be 50 or 30000
I've got an idea...
This line deletes the negative data.
How could I change:
if not b1 then listview1.items.delete(i1) ;
So, it will append the data on listview1 after the search?
In other words:
1. Display the result (As it's already doing)
2. Instead of deleting the results: if not b1 then listview1.items.delete(i1) ;
Add them to the end of the list.
Can this be done without using 2 listview's?
I've got an idea...
This line deletes the negative data.
How could I change:
if not b1 then listview1.items.delete(i1)
So, it will append the data on listview1 after the search?
In other words:
1. Display the result (As it's already doing)
2. Instead of deleting the results: if not b1 then listview1.items.delete(i1)
Add them to the end of the list.
Can this be done without using 2 listview's?
that is what rfwoolf is suggesting, it works, but you're 'non hits' will have reversed order.
If this is a problem best is to temporary place the 'non hits' in a container and add them to the list afterwards.
If this is a problem best is to temporary place the 'non hits' in a container and add them to the list afterwards.
ASKER
Would it be possible to help some example code please?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
That was spot on!!!
Perfect!!!
Thanks a million :o)
ST3VO
Perfect!!!
Thanks a million :o)
ST3VO
In your listview you are deleting all the negative results
Perhaps you should have two listviews: Listview1 and Listview2
Go through Listview1 and if a search is positive, add it to the TOP of Listview 2
If a search is negative, add it to the BOTTOM of Listview 2.
Then display Listview 2.