Recent

Author Topic: [CLOSED] ListView vsReport Search  (Read 7310 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 533
[CLOSED] ListView vsReport Search
« on: December 03, 2021, 07:23:49 pm »
I wrote the code for the ListView search engine, but it does not mark the items, what do I need to correct?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.BitBtn4Click(Sender: TObject);
  2. var
  3.   i, licznik: integer;
  4. begin
  5.   licznik := 0;
  6.   for i:=0 to ListView1.Items.Count -1 do
  7.   begin
  8.        ListView1.Items[i].Selected := false;
  9.         if pos(Edit5.Text, ListView1.Items[i].Caption)<>0 then
  10.         begin
  11.           ListView1.Items[i].Selected := true;
  12.           licznik := licznik+1;
  13.         end;
  14.   end;
  15.   if licznik=0 then showmessage('Not Found');
  16.  
  17. end;
« Last Edit: December 04, 2021, 05:19:43 pm by Pe3s »

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: ListView vsReport Search
« Reply #1 on: December 04, 2021, 07:28:09 am »
Yes, Multiselect: = True;

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: ListView vsReport Search
« Reply #2 on: December 04, 2021, 08:03:48 am »
listview by default does not show a selection unless focus is set on it.
You can either enable showing the selection:
Code: Pascal  [Select][+][-]
  1. ListView1.HideSelection := False;
or set focus on the listview after the search is complete
Code: Pascal  [Select][+][-]
  1.   if licznik = 0 then
  2.     ShowMessage('Not Found')
  3.   else
  4.     ListView1.SetFocus;
Best regards / Pozdrawiam
paweld

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: ListView vsReport Search
« Reply #3 on: December 04, 2021, 10:13:17 am »
Thank you, I have one more question, what do I have to change in the code to find each matching element in turn?

paweld

  • Hero Member
  • *****
  • Posts: 970
Re: ListView vsReport Search
« Reply #4 on: December 04, 2021, 12:11:30 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.BitBtn4Click(Sender: TObject);
  2. var
  3.   i, s: Integer;
  4.   found: Boolean;
  5. begin
  6.   if ListView1.Items.Count = 0 then
  7.     exit;
  8.   found := False;
  9.   ListView1.MultiSelect := False;
  10.   ListView1.HideSelection := False;
  11.   s := 0;
  12.   if Assigned(ListView1.Selected) then
  13.     s := ListView1.Selected.Index;
  14.   if s < ListView1.Items.Count - 1 then
  15.     i := s + 1
  16.   else
  17.     i := 0;
  18.   while not found do
  19.   begin
  20.     if pos(Edit5.Text, ListView1.Items[i].Caption) > 0 then
  21.     begin
  22.       ListView1.Items[i].Selected := True;
  23.       found := True;
  24.       break;
  25.     end
  26.     else
  27.     begin
  28.       if i = s then
  29.         break
  30.       else if i < ListView1.Items.Count - 1 then
  31.         Inc(i)
  32.       else
  33.         i := 0;
  34.     end;
  35.   end;
  36.   if not found then
  37.     ShowMessage('Not found');
Best regards / Pozdrawiam
paweld

Pe3s

  • Hero Member
  • *****
  • Posts: 533
Re: ListView vsReport Search
« Reply #5 on: December 04, 2021, 05:19:23 pm »
@paweld Thank you

 

TinyPortal © 2005-2018