Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I'm working with a datagridview that is linked to a DataSet and is editable by the user.
When the user changes a value and presses the save button, DataSet.HasChanges() returns false.
The changes made in the modified row in the datagridview have not been committed though can be by selecting a different row (by pressing enter or clicking).

But users tend to forget doing so and therefor brings the question;
How can I force the datagridview to commit any changes made to it's rows?
Posted
Updated 3-Dec-17 1:48am
v2

1 solution

Hi,
There are two DatgridView properties which should help solve this problem, IsCurrentCellDirty[^] and IsCurrentRowDirty[^], If there are uncommitted cells then call CommitEdit with the argument DataGridViewDataErrorContexts.Commit.

Another possibility is to examine IsCurrentCellInEditMode and call EndEdit on the cell.

Alan.
 
Share this answer
 
Comments
Groulien 29-Apr-11 15:44pm    
It worked!
--My implementation for documentation/google purposes--
It works by iterating through all the cells (CurrentCell property) and then using IsCurrentCellDirty and EndEdit.
sumitk.cadc 3-Dec-17 7:49am    
hi all ,
i want to achieve same thing in WPF datagrid please tell me how to to do this in WPF?
TIA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900