2014-12-09 1 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); 
} 

그래서 CodeValue로 검색해야 할 경우 comboBox의 색인을 얻을 수 있습니다.콤보 상자에서 색인 값을 가져 오는 방법은 무엇입니까?

답변

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); 
관련 문제