清除Firemonkey TListView搜索文本

时间:2016-07-08 12:34:12

标签: delphi firemonkey delphi-xe8

ListView1.items.filter := nil;

据我所知,以上内容将清除listview的过滤器,但是如果列表视图中显示搜索并且输入了某些内容,是否还要清除文本?

2 个答案:

答案 0 :(得分:6)

for I := 0 to ListView1.Controls.Count-1 do
  if ListView1.Controls[I] is TSearchBox then
  begin
    TSearchBox(ListView1.Controls[I]).Text := '';
  end;

(基于DocWiki!)

答案 1 :(得分:1)

感谢@Dsm,回答。我只是建议一个技巧,让TSearchBox只有一次并存储在一个变量中。现在没有必要每次循环TListView.Controls。例如:

uses
 ..., FMX.SearchBox;

var
  SearchBox_ListView1: TSearchBox = nil;

...

if not Assigned(searchBox_listview1) then 
  for I := 0 to ListView1.Controls.Count-1 do
    if ListView1.Controls[I] is TSearchBox then
    begin
      SearchBox_listview1 := TSearchBox(ListView1.Controls[I]);
      Break;
    End;

... 

if Assigned(SearchBox_listview1) then
  SearchBox_listview1.Text := '';