What is the correct order of processing an insert from a data-bound control using BindingSource, DataSet, and TableAdapter? This is causing me eternal confusion.
I have a form that is used to add a new row.
Before showing the form, I call:
bindingSource.AddNew();
bindingSource.MoveLast();
Upon Save, I call:
bindingSource.EndEdit();
tableAdapter.Insert([the row given to me as bindingSource.Current]);
The problem is that
- if I don't call EndEdit(), the changes of the TextBox with the current focus are not saved
- if I do call EndEdit(), the BindingSource's Current member no longer points to the row that I just added.
I can of course call Insert() with the values from the form as opposed to the DataTable that was updated by the BindingSource, but that defeats the purpose of using data binding. What do I need to do in order to get this working?
Edit: I understand that I could call TableAdapter.Update() on the entire DataSet, since I am using a strongly typed DataSet. I have foreign keys in the table that are not datab-bound, though, and that I am adding in before I call Insert().