-2
2つのドロップダウンリストを同じローカルデータベースにリンクする方法ですが、2つのドロップダウンリストで同じ値が選択されている場合はエラーメッセージが表示されます。Visual Studioのドロップダウンリスト
2つのドロップダウンリストを同じローカルデータベースにリンクする方法ですが、2つのドロップダウンリストで同じ値が選択されている場合はエラーメッセージが表示されます。Visual Studioのドロップダウンリスト
ComboBox1
とComboBox2
とすると、あなたがすることができる簡単なことは、これらの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
}