ListBox
有一个非常简单的方法来寻找它里面的字符串:德尔福 - 等效字符串列表框搜索的ListView
if ListBox1.Items.IndexOf('yourString') > -1 then
begin
//arriba
end;
是否有搜索string
但使用ListView
等效的方法吗?
ListBox
有一个非常简单的方法来寻找它里面的字符串:德尔福 - 等效字符串列表框搜索的ListView
if ListBox1.Items.IndexOf('yourString') > -1 then
begin
//arriba
end;
是否有搜索string
但使用ListView
等效的方法吗?
使用FindCaption
方法TListView
。
也许这就是你正在寻找Swissdelphicenter似乎有一个快速的解决方案Link to the article
呼叫FindCaption方法来搜索由指定为Value参数 串标列表视图项
我不是一个专家FMX但不能使用:
FMX.ListView.TListViewBase.SearchVisible
有关详细信息,使用此Link
显示在您的列表视图的顶部,可以过滤列表的内容的搜索框。
我宁愿在不使用'loop'语句的情况下搜索它。因此,'SearchVisible'用于搜索ListItems。我想搜索列表中的字符串以避免添加重复的项目。 – Machado
试试这个:
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;
我正在使用'Firemonkey'。它看起来像这个方法不存在。 – Machado
@tardoandre你应该在你的问题中这么说。 –
我一直把它放在几乎所有的问题上,人们总是去掉标签。 – Machado