Using C # Entity Framework objects like below 2
paragraph:
- ItemName
- itemtypeid
- itemprice
- itemsize
ItemType:
- Typeid
- Type Name
- currentprice
- typesize
In the item editing form, there is a combobox called typeidComboBox associated with loading the item.itemtypeid data source and item list from the itemtype data source.
When the Loads Binding Sources forms will be set as.
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; }
The problem occurs when I add some code, as shown below in the SelectionChangeCommitted event.
code:
private void typeidComboBox_SelectionChangeCommitted(object sender, EventArgs e) { (itemBindingSource.Current as item).itemprice = (itemtypeBindingSource.Current as itemtype).currentprice; }
Why does Combobox cancel the selection and maintain the old value when the SelectionChangeCommitted event is processed as the Combobox BindingSource property changed in it?
Sorry, my English.
source share