2016-09-03 5 views

답변

0

ComboBox1ComboBox2으로 가정합니다. 당신이 할 수있는 간단한 일은이 두 개의 Controls이 같은 값을 가지고 있는지 확인하고 두 컨트롤의 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 
}