I have a Windows form bound to a DataTable through a BindingSource. When I call EndEdit on this BindingSource, it does not always change DataTable to show the modifications, and calling GetChanges on the DataSet returns null.

Here's the situation in more detail - I have a DataSet, and a BindingSource bound to that dataset. There is then a BindingSource bound to the Regulators table in the DataSet. It looks something like this (summary) :

m_bs = new BindingSource(dataSet);
m_regulatorsBs = new BindingSource(m_bs, "Regulators");

I have a list of choices in a DataGridView, bound to this second BindingSource:

mainView.DataSource = m_regulatorsBs;

I then have a details control, with many controls bound to the same BindingSource. When a user clicks on an item in the DataGridView, the position of the BindingSource changes and the new record's details are shown on the details control. So far so good.

But before saving data, I want to make sure that any edits are committed to the DataTable again. To do this I call:


Now here's the wierd thing. This works only when I'm viewing the first record. Doing this with subsequent records seems to have no effect. The DataTable does not show any modifications. Oddly, if I get the DataRowView that the BindingSource is pointing to, and call EndEdit on this, it works:

DataRowView drv = (DataRowView)m_regulatorsBs.Current;

But I'd rather not make any assumptions about what the BindingSource is pointing to, and EndEdit is supposed to do this anyway, as far as I understand.

Does anyone know why this might be working only for the first record? Is it a known bug?



8 Years
Discussion Span
Last Post by LizR

No I do that if there are changes. That is in code further down the line - pseudo code is:

if myDataSet.GetChanges() != null
Pass result of GetChanges() to server to commit data

The problem is that no changes show up in the DataSet to update, so nothing is passed back to the server to save.

Calling EndEdit should propagate the changes made in the bound controls into the DataTable, but the problem is that calling EndEdit() on the BindingSource does not call EndEdit() on the underlying DataRowView, unless it is pointing to the first record. The documentation suggests that it should always be calling EndEdit() on the underlying data source. Currently I have to cast the data source to a DataRowView and call EndEdit() myself, which is not ideal.


Then Id need to see more context, because without seeing more theres no chance of saying why its not working


Ok, we're in the throes of getting the first version released, but I'll plan to try and narrow it down to some code I can post in a few days.


ok. If it works for 1 record but not the others, theres most certainly something going wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.