[英]get index of item in listbox c#
我正在嘗試獲取列表框中每個項目的索引,這是我的代碼
foreach (ListItem lstItem in lstCostCenter.Items)
{
int x = lstCostCenter.Items.IndexOf(lstItem);
}
但每次其僅返回0。
請有人幫我。
感謝Gulrej
為什么不使用for循環?
for (int i = 0; i < lstCostCenter.Items.Count; i++)
{
ListItem lstItem = lstCostCenter.Items[i];
}
當前項目的索引是i
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.