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

Delphi-ListView的等效ListBox字符串搜索,listview,delphi,search,firemonkey,Listview,Delphi,Search,Firemonkey,ListBox有一种非常简单的方法来搜索其中的字符串: if ListBox1.Items.IndexOf('yourString') > -1 then begin //arriba end; 是否有一种搜索字符串的等效方法,但使用列表视图?使用列表视图的方法使用列表视图的方法也许这就是您正在搜索的Swissdelphicenter似乎有一个快速解决方案 调用FindCaption方法来搜索由 指定为值参数的字符串 我不是FMX专家,但你不能使用: FMX.ListView.TLi

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

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

是否有一种搜索
字符串的等效方法,但使用
列表视图

使用
列表视图的方法

使用
列表视图的方法

也许这就是您正在搜索的Swissdelphicenter似乎有一个快速解决方案

调用FindCaption方法来搜索由 指定为值参数的字符串

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

FMX.ListView.TListViewBase.SearchVisible

有关更多详细信息,请使用此

在列表视图顶部显示一个搜索框,可以筛选列表内容


也许这就是你正在搜索的东西瑞士德尔菲中心似乎有一个快速的解决方案

调用FindCaption方法来搜索由 指定为值参数的字符串

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

FMX.ListView.TListViewBase.SearchVisible

有关更多详细信息,请使用此

在列表视图顶部显示一个搜索框,可以筛选列表内容

试试这个:

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;
试试这个:

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;

因此,创建帮助器。格式单位:

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;

因此,创建帮助器。格式单位:

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;

我正在使用
Firemonkey
。看起来这个方法不存在。@tardoandre你应该在你的问题中这样说。我几乎把它放在每个问题上,人们总是删除标记。你应该在问题本身中这样说,而不仅仅是用[firemonkey]标记它。我正在使用
firemonkey
。看起来这个方法不存在。@tardoandre你应该在你的问题中这样说。我几乎把它放在每个问题上,人们总是删除标记。你应该在问题本身中这样说,而不仅仅是用[firemonkey]标记它。我宁愿搜索它而不使用
循环
语句。因此,
SearchVisible
用于搜索列表项。我希望在列表中搜索字符串以避免添加重复的项。我希望搜索它时不使用
循环
语句。因此,
SearchVisible
用于搜索列表项。我想在列表中搜索字符串,以避免添加重复项。