Clear Firemonkey TListView search text

无人久伴 提交于 2019-12-22 12:40:49

问题


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

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