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