清除 Firemonkey TListView 搜索文本
Clear Firemonkey TListView search text
ListView1.items.filter := nil;
我知道上面的内容会清除列表视图的过滤器,但是如果 Search 对列表视图可见并且输入了一些内容,是否有清除文本的方法来自它?
for I := 0 to ListView1.Controls.Count-1 do
if ListView1.Controls[I] is TSearchBox then
begin
TSearchBox(ListView1.Controls[I]).Text := '';
end;
(基于 DocWiki!)
感谢@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 := '';
ListView1.items.filter := nil;
我知道上面的内容会清除列表视图的过滤器,但是如果 Search 对列表视图可见并且输入了一些内容,是否有清除文本的方法来自它?
for I := 0 to ListView1.Controls.Count-1 do
if ListView1.Controls[I] is TSearchBox then
begin
TSearchBox(ListView1.Controls[I]).Text := '';
end;
(基于 DocWiki!)
感谢@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 := '';