Delphi - ListView的等效ListBox字符串搜索

时间:2016-06-07 18:19:15

标签: listview delphi search firemonkey

ListBox有一种非常简单的方法可以搜索其中的字符串:

if ListBox1.Items.IndexOf('yourString') > -1 then
begin
  //arriba
end;

是否有相同的方法来搜索string但使用ListView

4 个答案:

答案 0 :(得分:3)

使用TListView的{​​{3}}方法。

答案 1 :(得分:2)

也许这就是您正在寻找的Swissdelphicenter似乎有一个快速的解决方案Link to the article

  

调用FindCaption方法以搜索标记为的列表视图项     指定为Value参数的字符串

我不是FMX专家,但你不能使用:

FMX.ListView.TListViewBase.SearchVisible

有关详细信息,请使用此Link

  

在列表视图顶部显示一个搜索框,可以过滤列表内容。

答案 2 :(得分:0)

试试这个:

procedure SarchLV(SearchStr: String);
begin

  SearchStr := LowerCase(SearchStr);

  ListView1.Items.Filter :=
    Function(X: string): Boolean
    Begin
       Result:= (SearchStr = EmptyStr) Or LowerCase(X).Contains(SearchStr);
     End;

end;

答案 3 :(得分:0)

所以创造助手。形式单位:

THelperListView = class helper for TListView
public
  function FindCaption(const aText: string): boolean;
end;

function THelperListView.FindCaption(const aText: string): boolean;
var
  i: Integer;
begin
  Result := false;
  for i := 0 to Items.Count - 1 do
  begin
    Result := CompareText(Items[i].Text, aText) = 0;
    if Result then
      exit;
  end;
end;
相关问题