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?
c # winforms entity-framework bindingsource
Randy
source share