Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3080
  • Last Modified:

DataGridView EndEdit/AcceptChanges

I have a DataGridView and when the user checks a checkbox in a row and closes the form immediately as the next click, I would like to display a message to the user saying 'changes not saved'.

When I call underlying DataTable.GetChanges(), it's always returning null. So on the form close I'm calling DataGridView.EndEdit() method. After this call, I see the datatable is updated with the last change by the user, but DataTable.GetChanges() is still returing null. Any ideas on this?
0
praveenuni
Asked:
praveenuni
  • 2
1 Solution
 
oobaylyCommented:
When is the Update query being run? Is it in your DataTable.RowChanged event?
It's quite possible that when datagridview is losing focus (when you click the form's close button), the changes are being sent to the database. If you're using an SqlDataAdapter to execute these changes then it will set the RowState to Unchanged for all the rows.
Calling GetChanges on the DataTable will return a null reference as there are no changes to be done.
0
 
praveenuniAuthor Commented:
There is no update or DataAdapter. I'm just using a plain dataset with some test data( with no connection to database). I found a link, which shows this as a bug http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=92329

I'm wondering if there is a fix for this?
0
 
oobaylyCommented:
Strange, I can't replicate this problem. I've added a DataGridView to the form.
Hook the FormClosing event.
In the constructor create as basic table that has a boolean column, populate with some random data. Accept changes on the DataTable (and verify GetChanges() returns null)
Set the DataTable as the datasource for the DataGridView.
Change the checkstate of a row, and close the form.
In FormClosing,AcceptChanges() on the DataGridView, GetChanges() returns a table with a single row.

Are you doing anything wildly different from the above?
Can you confirm the contents of the datatable after you call AcceptChanges (rather than using GetChanges())?
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now