【发布时间】:2016-06-07 18:19:14
【问题描述】:
ListBox 有一种非常简单的方法可以在其中搜索字符串:
if ListBox1.Items.IndexOf('yourString') > -1 then
begin
//arriba
end;
是否有等效的方法来搜索string,但使用ListView?
【问题讨论】:
标签: listview delphi search firemonkey
ListBox 有一种非常简单的方法可以在其中搜索字符串:
if ListBox1.Items.IndexOf('yourString') > -1 then
begin
//arriba
end;
是否有等效的方法来搜索string,但使用ListView?
【问题讨论】:
标签: listview delphi search firemonkey
使用TListView的FindCaption方法。
【讨论】:
Firemonkey。这个方法好像不存在。
也许这就是您要搜索的内容 Swissdelphicenter 似乎有一个快速的解决方案Link to the article
调用 FindCaption 方法来搜索由 指定为 Value 参数的字符串
我不是 FMX 专家,但你不能使用:
FMX.ListView.TListViewBase.SearchVisible
更多详情请使用Link
在列表视图顶部显示一个可以过滤列表内容的搜索框。
【讨论】:
loop 语句。因此,SearchVisible 用于搜索 ListItems。我想在 List 中搜索字符串以避免添加重复项。
试试这个:
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;
【讨论】: