【问题标题】:Delphi - Equivalent ListBox string search for ListViewDelphi - ListView 的等效 ListBox 字符串搜索
【发布时间】:2016-06-07 18:19:14
【问题描述】:

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

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

是否有等效的方法来搜索string,但使用ListView

【问题讨论】:

    标签: listview delphi search firemonkey


    【解决方案1】:

    使用TListViewFindCaption方法。

    【讨论】:

    • 我正在使用Firemonkey。这个方法好像不存在。
    • @tardoandre 你应该在你的问题中这么说。
    • 我几乎在每个问题上都使用了它,人们总是在删除标签。
    • 您应该在问题本身中这样说,而不仅仅是用 [firemonkey] 标记它
    【解决方案2】:

    也许这就是您要搜索的内容 Swissdelphicenter 似乎有一个快速的解决方案Link to the article

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

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

    FMX.ListView.TListViewBase.SearchVisible

    更多详情请使用Link

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

    【讨论】:

    • 我宁愿搜索它而不使用loop 语句。因此,SearchVisible 用于搜索 ListItems。我想在 List 中搜索字符串以避免添加重复项。
    【解决方案3】:

    试试这个:

    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;
    

    【讨论】:

      【解决方案4】:

      所以创建助手。在表单单元中:

      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;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-08
        • 1970-01-01
        • 1970-01-01
        • 2015-02-05
        • 2011-10-21
        • 1970-01-01
        • 2018-05-22
        • 1970-01-01
        相关资源
        最近更新 更多