简体   繁体   中英

Combo Box Data Binding

Hopefully someone has seen this before and can see my mistake:

I am binding a combo box selected value to a data set and the first time I change the combo box selected value, it does not update in the data set ie the values don't match. If I change the selected value a second time it works as expected and my data set updates to match the combo box.

I am also using a second data set for the Data Source which populates the list of items with text (for the user) but provides an index to save in the first data set.

comboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", dataView1, "mode", true));
comboBox.DataSource = dataView2;
comboBox.DisplayMember = "list_str.str_text";
comboBox.ValueMember = "list_str.index";            

Any idea why the data set does not update the first time the selected value changes?

EDIT: I may not have been clear originally but I'm not binding directly to the data set - I am using a data view since I have multiple tables in the data set. Is it possible to use the data view to automatically save back to the data set? Should I close this and open a new question?

Try ComboBox.SelectedIndexChanged instead.

http://devpinoy.org/blogs/joeycalisay/archive/2005/11/23/Combobox-SelectedIndexChanged-vs-SelectionChangeCommitted.aspx

SelectedIndexChanged * raised when DataSource is set * raised when SelectedIndex is set programmatically

SelectionChangeCommitted * not raised when DataSource is set * not raised when SelectedIndex is set programmatically

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM