troubleshooting Question

DataGridView with BindingSource not updating dataset

Avatar of pigparent
pigparent asked on
.NET ProgrammingVisual Basic.NET
5 Comments1 Solution1955 ViewsLast Modified:
I have a DataGridView (dgvEncumbr) that is bound to a business object dataset property (oPO.Encumbrances) by way of a BindingSource (bsEncumbr), as shown below under "Bind DataGridView".

When a user attempts to add a new object (oPO), I am resetting the binding to make sure there is no risidual from an earlier selection.  When the user clicks the save button (buttonSavePO), I am updating the BindingSource like so:  bsEncumbr.EndEdit().

The trouble is that it will not save the dgv entries until after the oPO object is saved once.  When I step through the code, I find that bsEncumbr.EndEdit has the new records from the dataset, but it isn't making it from bsEncumbr to the dataset in the business object.  This actually used to work and it stopped.  Am I missing some code that will update the business object (dataset) from the BindingSource?
'Bind DataGridView
bsEncumbr.DataSource = oPO.Encumbrances
bsEncumbr.DataMember = "POEncumbrances"
dgvEncumbr.DataSource = bsEncumbr
bsEncumbr.EndEdit()  'records are present at runtime
'code in the business object's Save() method
m_daEncumbr.Update(m_dsEncumbr, "POEncumbrances")  'records are NOT present in the dataset!

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros