2016-09-03 23 views

答えて

0

ComboBox1ComboBox2とすると、あなたがすることができる簡単なことは、これらの2つが同じ値を持っているかどうかを検証し、両方のコントロールのSelectedIndexChagedイベントでそれを発生させるかどうかを確認するbool methodを作成することです。

private bool IsComboBoxSameValue() 
{ 
    if(ComboBox1.SelectedItem.ToString() == ComboBox2.SelectedItem.ToString() 
    { 
     MessageBox.Show("The ComboBoxes have the same value"); 
     return true; // the ComboBoxes has the same value 
    } 
    else 
    { 
     return false; // the comboboxes has different value 
    } 
} 

のようにそれを使用します。

ComboBox1_SelectedItemChanged(object sender, EventArgs e) 
{ 
    if(IsComboBoxSameValue()) 
     return; 

    // do long running work here after you validated that the ComboBoxes have different value 
} 
関連する問題