2014-12-09 2 views
0
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); 
} 

Так как я могу получить индекс comboBox, если мне нужно искать по CodeValue.Как получить значение индекса в поле со списком?

ответ

0

Использование foreach

Int i = 0; 

foreach(var item in myComboBox.Items) 
{ 
    if(item.CodeValue = SearchCodeValue) 
    { 
     return i // result index 
    } 
    else 
    { 
     i = i + 1; 
    } 
} 
0

Вы можете попробовать:

var index = Array.FindIndex<CustomComboItem>(ComboBox1.Items.Cast<CustomComboItem>().ToArray<CustomComboItem>(), item => item.CodeValue == SearchCodeValue); 
Смежные вопросы