public class CustomComboItem
{
public Double CodeValue { get; set; }
public String DisplayName { get; set; }
public String Description { get; set; }
}
for (int i = 0; i < locCnt; ++i)
{ //I am setting member variable of CustomComboItem
// and add to the combobox
ComboBox1.Items.Add(customComboItem1);
}
如果我需要按CodeValue搜索,那么如何获取comboBox的索引。
答案 0 :(得分:0)
使用foreach
Int i = 0;
foreach(var item in myComboBox.Items)
{
if(item.CodeValue = SearchCodeValue)
{
return i // result index
}
else
{
i = i + 1;
}
}
答案 1 :(得分:0)
您可以尝试:
var index = Array.FindIndex<CustomComboItem>(ComboBox1.Items.Cast<CustomComboItem>().ToArray<CustomComboItem>(), item => item.CodeValue == SearchCodeValue);