Home > database >  underlying datatable doesn't get the row from datagridview
underlying datatable doesn't get the row from datagridview

Time:07-01

Now, this one can be very obvious for someone, but I am stuck right on this:

Datagridview is bound to a binding source and the binding source is bound to a datatable.

Datagridview is now showing an empty row (with an asterisk).

enter image description here

When I click on a cell a cursor icon appears near that asterisk.

enter image description here

Now I am entering data in that row. When I enter a value in the first cell, a new row appears underneath this one, and the asterisk icon moves to that row. CellValueChanged gets fired, BUT in the watch window, the datatable still doesn't have that row.

enter image description here

enter image description here

I am finishing all columns and hitting a save button, BUT still in the watch window is see that the underlying datatable is not holding that row.

enter image description here

How to get that change back to datatable? Do I need to call some method after clicking that save button? I've tried with _detailDataTable.AcceptChanges(); but nothing happened.

CodePudding user response:

Call EndEdit on the BindingSource. DEFINITELY do not call AcceptChanges! That doesn't get called until you have actually saved the changes. It will be invoked implicitly when you call Update on your adapter. If you call it first then there will be no changes to save.

  • Related