FireMonkey TListview Search Reload Issue

偶尔善良 提交于 2019-12-06 04:02:43

问题


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;

来源:https://stackoverflow.com/questions/25248261/firemonkey-tlistview-search-reload-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!