以下の 2 のような C# Entity Framework オブジェクトの使用
アイテム:
- 項目名
- itemtypeid
- アイテムの価格
- アイテムサイズ
アイテムタイプ:
- typeid
- タイプ名
- 現在の価格
- タイプサイズ
アイテム編集フォームには、item.itemtypeid にバインドされた typeidComboBox と呼ばれるコンボボックスと、itemtype データソースから読み込まれるアイテム リスト データソースがあります。
フォームが読み込まれると、バインディング ソースが次のように設定されます。
private void Form1_Load(object sender, EventArgs e)
{
db = new dbtestEntities();
itemtypeBindingSource.DataSource = db.usertypes;
itemBindingSource.DataSource = db.users;
typeidComboBox.DataBindings.Clear();
typeidComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.itemBindingSource, "itemtypeid", true));
typeidComboBox.DataSource = this.itemtypeBindingSource;
typeidComboBox.DisplayMember = "typename";
typeidComboBox.ValueMember = "typeid";
typeidComboBox.SelectionChangeCommitted += typeidComboBox_SelectionChangeCommitted;
}
SelectionChangeCommitted イベントに以下のようなコードを追加すると、問題が発生します。
コード:
private void typeidComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
(itemBindingSource.Current as item).itemprice = (itemtypeBindingSource.Current as itemtype).currentprice;
}
SelectionChangeCommitted イベントがコンボボックスの BindingSource プロパティが変更されたように処理されたときに、コンボボックスの選択がキャンセルされて古い値に戻るのはなぜですか?
申し訳ありませんが私の英語。