Why do I need to change the position of the binding source before I can SaveChanges

I have a small WinForms demo application. One form is my "Add a new person" form. I used the Details view instead of the DataGridView from my data sources. When I enter the data and click the "Save" button in the Navigator, the zero changes change. However, after AddNew on the Load form, I put MovePrevious and MovePrevious , everything works as expected.

 public partial class AddPersonForm : Form { private readonly DemoContext _context; public AddPersonForm() { _context = new DemoContext(); InitializeComponent(); } protected override void OnLoad(EventArgs e) { _context.People.Load(); personBindingSource.DataSource = _context.People.Local.ToBindingList(); personBindingSource.AddNew(); personBindingSource.MovePrevious(); personBindingSource.MoveNext(); base.OnLoad(e); } private void personBindingNavigatorSaveItem_Click(object sender, EventArgs e) { int changes = _context.SaveChanges(); Debug.WriteLine("# of changes: " + changes); } } 

Why do I need to switch the position of the BindingSource before it knows the changes and saves?

+8
c # winforms entity-framework bindingsource
source share
1 answer

You do not need to change the position, in fact you need to call BindingSource.EndEdit , which applies the pending source data source,

Changing the position leads to the fact that the main currency call manager is EndCurrentEdit , and this is what the EndEdit source binding method does for you.

+3
source share

All Articles