[英]How to find an Item's index in a Firemonkey TListBox?
我的目標是更新ItemIndex
一個的TListBox
,以一種編程方式將項目添加到列表時,相應的線路上列出TListBox
。
我試過:
with MyLstBox do begin
ItemIndex := -1;
for ind := 0 to Pred (Items.Count) do
if InsertedString = Items [ind]) then begin
ItemIndex := Ind;
Break;
end;
end;
此代碼概述了剛剛插入的項目,但也保留了前一個插入項目的輪廓。
MultiSelect
設置為False
,因此原則上只應勾勒出一項。
Items
屬性是一個TStrings
對象。 您可以使用TStrings.IndexOf()
方法而不是手動循環:
MyLstBox.ItemIndex := MyLstBox.Items.IndexOf(InsertedString);
當您向 ListBox 添加新項目時, TStrings.Add()
方法返回新項目的索引:
MyLstBox.ItemIndex := MyLstBox.Items.Add(InsertedString);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.