-2
두 개의 드롭 다운 목록을 동일한 로컬 db로 연결하는 방법 두 개의 드롭 다운 목록에서 동일한 값을 선택한 경우 오류 메시지가 표시됩니다.Visual Studio의 드롭 다운 목록
두 개의 드롭 다운 목록을 동일한 로컬 db로 연결하는 방법 두 개의 드롭 다운 목록에서 동일한 값을 선택한 경우 오류 메시지가 표시됩니다.Visual Studio의 드롭 다운 목록
ComboBox1
및 ComboBox2
으로 가정합니다. 당신이 할 수있는 간단한 일은이 두 개의 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
}