2016-06-07 41 views

回答

3

使用FindCaption方法TListView

+0

我正在使用'Firemonkey'。它看起來像這個方法不存在。 – Machado

+1

@tardoandre你應該在你的問題中這麼說。 –

+0

我一直把它放在幾乎所有的問題上,人們總是去掉標籤。 – Machado

2

也許這就是你正在尋找Swissdelphicenter似乎有一個快速的解決方案Link to the article

呼叫FindCaption方法來搜索由指定爲Value參數 串標列表視圖項

我不是一個專家FMX但不能使用:

FMX.ListView.TListViewBase.SearchVisible

有關詳細信息,使用此Link

顯示在您的列表視圖的頂部,可以過濾列表的內容的搜索框。

+0

我寧願在不使用'loop'語句的情況下搜索它。因此,'SearchVisible'用於搜索ListItems。我想搜索列表中的字符串以避免添加重複的項目。 – Machado

0

試試這個:

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; 
0

因此,創建幫手。在表單元中:

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;