5

TListview is not reloading properly when you do a search, clear the search and then reload the listview. Using XE5.

Steps are:

  1. After project is running enter text into search.
  2. Clear search either clicking on "Clear" button or deleting the search text or clicking on the search "X" button.
  3. Press the "Reload" button. Nothing appears. You can step through the reload procedure and see that each item is added. However, the resulting list count is "0"!!!
  4. However, if you add the search text back the items reappear. This is crazy. And you clear the search again and all items appear. Hit the reload button and they disappear.
  5. I have tried every trick I can to solve this and come up with nothing. Even when you clear the search, the listview is holding on to the search contents.
  6. So for now listview is a malfunctioning control. If you do a search you cannot clear the search and reload the listview.
  7. I have even tried TSearchBox and set "DeleteSelection", "ResetSelection" and "ClearSelection" <> None of these works.

Any help with this quirky thing???

Code is as follows:

procedure TForm1.FormCreate(Sender: TObject);
var
  i: integer;
  LItem: TListviewItem;
begin
  if Assigned(Listview1) then
    Listview1.Items.Clear;
  for i := 1 to 20 do
  begin
    LItem := Listview1.Items.Add;
    LItem.Text := IntToStr(i);
  end;
end;

procedure TForm1.btnButton1Click(Sender: TObject);  { reload button }
var
  i: integer;
  LItem: TListviewItem;
begin
  btnButton2Click(btnButton2);                <<<<edit add
  if Assigned(Listview1.Items.Filter) then    <<<<edit add
    Listview1.Items.Filter := nil;            <<<<edit add
  if Assigned(Listview1) then
    Listview1.Items.Clear;
  for i := 1 to 20 do
  begin
    LItem := Listview1.Items.Add;
    LItem.Text := IntToStr(i);
  end;
end;

procedure TForm1.btnButton2Click(Sender: TObject); { clear button }
var
  i: integer;
  SearchBox: TSearchBox;
begin
  for i := 0 to Listview1.Controls.Count - 1 do
    if Listview1.Controls[i].ClassType = TSearchBox then
    begin
      SearchBox := TSearchBox(Listview1.Controls[i]);
      Break;
    end;
  if Assigned(SearchBox) then      
    SearchBox.Text := '';
end;
t j
  • 413
  • 1
  • 7
  • 12
  • 3
    Never mind. I found my answer by setting "ListView1.Items.Filter := nil;" I will leave this up to help others because there is so little firemonkey help out there. I sometimes feel like I should be on their payroll for all of the wasted needless searching due to the lack of resources... – t j Aug 11 '14 at 16:47
  • I added 3 lines of code called "edit add". Works perfectly now. It does two things. (1) clears the search text and (2) nil the filter. Seems asinine to have to do both. Should be a part of the control to perform this as one seamless step. Duh. – t j Aug 11 '14 at 17:26
  • Today, I meet this bug in XE7. Thank you for your solution. – Leo Jan 05 '15 at 14:14
  • Almost the same on 10.2.1. Thanks! – dustypup Nov 23 '17 at 15:36

0 Answers0