问题
ListView1.items.filter := nil;
I understand that the above will clear the filter of a listview however if the Search is visible for the listview and something is typed into it, is there anyway of clearing the text from it?
回答1:
for I := 0 to ListView1.Controls.Count-1 do
if ListView1.Controls[I] is TSearchBox then
begin
TSearchBox(ListView1.Controls[I]).Text := '';
end;
(based on DocWiki!)
回答2:
Thanks @Dsm, by answer. I will just suggest a trick to get TSearchBox
just one time and store in a variable. Now it is not necessary to loop through the TListView.Controls
every time. For example:
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 := '';
来源:https://stackoverflow.com/questions/38266827/clear-firemonkey-tlistview-search-text