• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1395
  • Last Modified:

Datagridview Data Change Event

I have a datagridview linked to an Access database, and I want to prompt the user if they want to save the changes they make when they leave a row.  I have it working fine, only I wish to prompt them only if there is a change to the data in the row they leave.  Right now if the user is clicking the down arrow through the rows they are prompted each time they leave the row...not very good programming indeed!

Any help would be much appreciated.


Private Sub DataGridView1_RowLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowLeave
Dim Response
Response = MsgBox("Do you want to save changes?", MsgBoxStyle.YesNo, "Warning!")
If Response = vbYes Then
  Call SaveData()
End If
End Sub

Open in new window

0
bhlabelle
Asked:
bhlabelle
  • 2
1 Solution
 
nepaluzCommented:
If the grid is bound to the datasource, I am not sure if the data is not aved automatically, however, you could create a global variable to hold the value of the cell being EDITED by handling the CellBeginEdit and comparing the value in CellEndEdit. If the values are different, then call your prompt else be quiet!

0
 
bhlabelleAuthor Commented:
I like the idea.  I'll probably work on it later today and respond accordingly.

And the data is not saved automatically, at least how I have it set up.  I had to write an update command in the datasourceeditor.
0
 
bhlabelleAuthor Commented:
Thank, very easy to impliment.  I just added a string to set the value of the cell before the edit, added another string to set the value of the cell after the edit, if they are not the same then I prompt if the user wants to save the changes.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

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