2012-04-15 5 views

答えて

22

次のコードを使用して見つけることができます。

int index = comboBox1.Items.IndexOf(a); 

、アイテム自体を取得書き込むには:

comboBox1.Items[index]; 
0

私は私のソリューションは非常にシンプルで面白いですけど、私はそれを使用する前に訓練します。重要:コンボボックスのDropDownStyleは "DropDownList"でなければなりません!

コンボボックスで最初にして:それは私のために右の作品と私の問題を解決する... しかし、ST-mnmn @からの方法(ソリューション)は、より良いと罰金です

bool foundit = false; 
String mystr = "item_1"; 
mycombobox.Text = mystr; 
if (mycombobox.SelectedText == mystr) // Or using mycombobox.Text 
    foundit = true; 
else foundit = false; 

5

FindStringExact()のコンボボックスコントロールで、displaymemberを検索し、見つかった場合はその項目のインデックスを返すメソッドが表示されます。見つからなければ-1を返します。

//to select the item if found: 
mycombobox.SelectedIndex = mycombobox.FindStringExact("Combo"); 

//to test if the item exists: 
int i = mycombobox.FindStringExact("Combo"); 
if(i >= 0) 
{ 
    //exists 
} 
+0

FindExactString()は、ComboBoxのDisplayMemberプロパティで動作すると思います。私は、ComboBoxのValueMemberプロパティのマッチング方法について質問していると思います。 – andyabel

0

こんにちはGuysは最良の方法は、テキストまたは値を検索する場合は、

int Selected;  
int count = ComboBox1.Items.Count; 
    for (int i = 0; (i<= (count - 1)); i++) 
    {   
     ComboBox1.SelectedIndex = i; 
     if ((string)(ComboBox1.SelectedValue) == "SearchValue") 
     { 
      Selected = i; 
     } 

    } 

    ComboBox1.SelectedIndex = Selected; 
関連する問題